import sys

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

dp = [[0 for j in range(w)] for i in range(h)]

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

maxWidth = 0

for i in range(0, h):

    for j in range(0, w):

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

        maxWidth |= dp[i][j]

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

            if maxWidth < dp[i][j]:

                maxWidth = dp[i][j]

print((maxWidth * maxWidth))
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 for j in range(w)] for i in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for i in range(h)]
maxWidth = 0
for i in range(0, h):
    for j in range(0, w):
        dp[i][j] = (G[i][j] + 1) % 2
        maxWidth |= dp[i][j]
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
            if maxWidth < dp[i][j]:
                maxWidth = dp[i][j]
print((maxWidth * maxWidth))

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))

-dp = [[0 for j in range(w)] for i in range(h)] -G = [[int(j) for j in sys.stdin.readline().split()] for i in range(h)] -maxWidth = 0 +dp = [[0] * w for _ in range(h)] +G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)] -        maxWidth |= dp[i][j] -            if maxWidth < dp[i][j]: -                maxWidth = dp[i][j] -print((maxWidth * maxWidth)) +print((max([max(item) for item in dp]) ** 2))