// AOJ DPL_3_A Largest Square
// 2018.5.4 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

short dp[1405][1405];

int largestSquare(int H, int W, char map[1405][1405])
{
	int r, c, t, ans;
	
	ans = 0;
	for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) {
		if (map[r][c]) dp[r][c] = 0;
		else {
			t = dp[r-1][c-1];
			if (t > 0 && dp[r  ][c-1] < t) t = dp[r  ][c-1];
			if (t > 0 && dp[r-1][c  ] < t) t = dp[r-1][c  ];
			dp[r][c] = ++t;
			if (t > ans) ans = t;
		}
	}
	return ans*ans;
}

char map[1405][1405];
int main()
{
	int H, W, r, c;

	H = in(), W = in();
	for (r = 1; r <= H; r++) for (c = 1; c <= W; c++) {
		map[r][c] = gc() & 0xf, gc();
	}
	printf("%d\n", largestSquare(H, W, map));
	return 0;
}

