#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1500;

int a[N][N];
int dp[N][N];
int GetMaxSqure(int h, int w)
{
	int maxl = 0;
	for (int i= 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
		{
			dp[i][j] = (a[i][j] + 1) % 2;	// 如果是空白 该处宽度就是1
			if (a[i][j] == 0) maxl = 1;		// 0|1 为1 存在一块空白maxl就是1
		}
	
	for (int i = 1; i < h; ++i)
	{
		for (int j = 1; j < w; ++j)
		{
			if (a[i][j] == 0)
			{
				dp[i][j] = min(dp[i-1][j-1], min(dp[i][j-1], dp[i-1][j])) + 1;
				maxl = max(maxl, dp[i][j]);
			}
			else dp[i][j] = 0;			
		}
	}
	return maxl * maxl;
}

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			scanf("%d", &a[i][j]);
		
	printf("%d\n", GetMaxSqure(n, m));
	
	return 0;
}
