# 숫자 정사각형 - BOJ

숫자 정사각형 - BOJ

import sys

N, M = map(int, input().split())
li = []
for i in range(N):
    li.append(list(sys.stdin.readline().rstrip()))
max_num = N * M
size = 1
while True:
    if max_num < size*size:
        size -= 1
        break
    else:
        size += 1
ret = 1
for i in range(N):
    for j in range(M):
        for k in range(1, size+1):
            if i+k < N and j+k < M:
                same = li[i][j]
                if same == li[i+k][j] and same == li[i][j+k] and same == li[i+k][j+k]:
                    ret = max(ret, k + 1)
print(ret*ret)