import sys

h, w = list(map(int, sys.stdin.readline().split()))

dp = [[0] * w for _ in range(h)]

G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]

for i in range(0, h):

    for j in range(0, w):

        dp[i][j] = (G[i][j] + 1) % 2

for i in range(1, h):

    for j in range(1, w):

        if(G[i][j] == 0):

            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1

print((max([max(item) for item in dp])**2))
import sys

h, w = list(map(int, sys.stdin.readline().split()))

dp = [[0] * w for _ in range(h)]

G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]

for x in range(h):

    dp[x][0] = 1 if G[x][0] == 0 else 0

for y in range(w):

    dp[0][y] = 1 if G[0][y] == 0 else 0

for i in range(1, h):

    for j in range(1, w):

        if(G[i][j] == 0):

            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1

print((max([max(item) for item in dp])**2))
import sys

h, w = list(map(int, sys.stdin.readline().split()))
dp = [[0] * w for _ in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]
for i in range(0, h):
    for j in range(0, w):
        dp[i][j] = (G[i][j] + 1) % 2
for i in range(1, h):
    for j in range(1, w):
        if G[i][j] == 0:
            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print((max([max(item) for item in dp]) ** 2))

import sys

h, w = list(map(int, sys.stdin.readline().split()))
dp = [[0] * w for _ in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]
for x in range(h):
    dp[x][0] = 1 if G[x][0] == 0 else 0
for y in range(w):
    dp[0][y] = 1 if G[0][y] == 0 else 0
for i in range(1, h):
    for j in range(1, w):
        if G[i][j] == 0:
            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print((max([max(item) for item in dp]) ** 2))

-for i in range(0, h): -    for j in range(0, w): -        dp[i][j] = (G[i][j] + 1) % 2 +for x in range(h): +    dp[x][0] = 1 if G[x][0] == 0 else 0 +for y in range(w): +    dp[0][y] = 1 if G[0][y] == 0 else 0