#include <stdio.h>
#include <algorithm>

int h, w;
int a[1401][1401];
int dp[1401][1401];

int main()
{
	scanf("%d%d", &h, &w);
	int res = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			scanf("%d", &a[i][j]);
			dp[i][j] = !a[i][j];
			res |= dp[i][j];
		}

	for (int i = 1; i < h; i++)
		for (int j = 1; j < w; j++)
		{
			if (a[i][j] == 0)
				dp[i][j] = std::min(std::min(dp[i - 1][j - 1], dp[i - 1][j]), dp[i][j - 1]) + 1;
			res = std::max(res, dp[i][j]);
		}

	printf("%d\n", res * res);

	return 0;
}

