import json
import sys
    
def input():
    return sys.stdin.readline().strip()
    
    
N, M = map(int, input().split(" "))
arr = []
for _ in range(N):
    arr.append(list(map(int, input())))
minValue = min(N, M)
for a in range(minValue-1, 0, -1):
    
    for y in range(N):
        for x in range(M):
            yIndex = y + a
            xIndex = x + a
        
            if(yIndex >= N or xIndex >= M):
                continue
            
            isSame = arr[y][x] == arr[y][xIndex] == arr[yIndex][x] == arr[yIndex][xIndex]
            
            if(isSame):
                
                line = xIndex - x + 1
                
                
                print(line * line)
                exit()
print(1)
참 막막했지만 해냈다...
제일 큰 정사각형을 찾는 문제이기 때문에
제일 큰것 > 작은것 순으로 찾으면 된다.
정사각형 변의 최대 길이는 min(N, M) 이다.
그래서 크기를 하나씩 낮출때마다 상하좌우로 이동하면서
꼭짓점들이 동일한게 있나~ 탐색해주면 된다.
찾을때까지.
없다면 1 출력