N, M = map(int, input().split())
map_lst = [list(map(int, input())) for _ in range(N)]
max = 0
for x1 in range(M-1):
for y1 in range(N-1):
for ad in range(1, M-x1):
if x1 + ad < M and y1 + ad < N:
if map_lst[y1 + ad][x1 + ad] == map_lst[y1][x1 + ad] == map_lst[y1 + ad][x1] == map_lst[y1][x1] and max < ad:
max = ad
print((max+1) ** 2)