import sys



def solve():

    file_input = sys.stdin

    H, W = list(map(int, file_input.readline().split()))

    dp = [[0] * (W + 1)]

    for line in file_input:

        dp.append([0] + list(map(int, line.split())))

    max_width = 0

    for i in range(1, H + 1):

        for j in range(1, W + 1):

            if dp[i][j] == 1:

                dp[i][j] = 0

            else:

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

                max_width = max(max_width, dp[i][j])

    print((max_width ** 2))



solve()
import sys



def solve():

    file_input = sys.stdin

    H, W = list(map(int, file_input.readline().split()))

    side_length = 0

    prev = [0] * (W + 1)

    for line in file_input:

        tile_line = list(map(int, line.split()))

        current = [0] * (W + 1)

        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1):

            t, p1, p2 = tpl

            if t:

                current[i] = 0

            else:

                current[i] = min(p1, p2, current[i - 1]) + 1

        prev = current

        side_length = max(side_length, max(current))

    print((side_length ** 2))



solve()
import sys


def solve():
    file_input = sys.stdin
    H, W = list(map(int, file_input.readline().split()))
    dp = [[0] * (W + 1)]
    for line in file_input:
        dp.append([0] + list(map(int, line.split())))
    max_width = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if dp[i][j] == 1:
                dp[i][j] = 0
            else:
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
                max_width = max(max_width, dp[i][j])
    print((max_width**2))


solve()

import sys


def solve():
    file_input = sys.stdin
    H, W = list(map(int, file_input.readline().split()))
    side_length = 0
    prev = [0] * (W + 1)
    for line in file_input:
        tile_line = list(map(int, line.split()))
        current = [0] * (W + 1)
        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1):
            t, p1, p2 = tpl
            if t:
                current[i] = 0
            else:
                current[i] = min(p1, p2, current[i - 1]) + 1
        prev = current
        side_length = max(side_length, max(current))
    print((side_length**2))


solve()

-    dp = [[0] * (W + 1)] +    side_length = 0 +    prev = [0] * (W + 1) -        dp.append([0] + list(map(int, line.split()))) -    max_width = 0 -    for i in range(1, H + 1): -        for j in range(1, W + 1): -            if dp[i][j] == 1: -                dp[i][j] = 0 +        tile_line = list(map(int, line.split())) +        current = [0] * (W + 1) +        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1): +            t, p1, p2 = tpl +            if t: +                current[i] = 0 -                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1 -                max_width = max(max_width, dp[i][j]) -    print((max_width**2)) +                current[i] = min(p1, p2, current[i - 1]) + 1 +        prev = current +        side_length = max(side_length, max(current)) +    print((side_length**2))