CSG-CPC
Online Judge

1024 : The Smallest Floor Tile

         Time Limit: 1 Sec     Memory Limit: 128 MB     Submitted: 1     Solved: 1    

Description

Xiao Ming saw a wide variety of patterns in a floor shop.

He wants to know how every floor can be paved with the smallest floor tiles.

Input

There are no more than 20 test cases.

The first line of each case contains two integer numbers n and m, indicating the length and width of the floor.

Then n lines, each line contains exactly m letters indicating the patterns.

1 <= n <= 500, 1 <= m <= 500, all the patterns are uppercase letters as A~Z.

Output

For each case, output two integer numbers indicating the size of the smallest tile that could make up this floor.

Sample

2 3
GNA
LTK
4 6
ABABAB
CDCDCD
ABABAB
CDCDCD
6 10
ASAZAASAZA
AQHZYAQHZY
ICYAAICYAA
ASAZAASAZA
AQHZYAQHZY
ICYAAICYAA
2 3
2 2
3 5

Hint

For example

ABABAB
CDCDCD
ABABAB
CDCDCD

The smallest tile is

AB
CD

Author

CSGrandeur