#include <bits/stdc++.h>
using namespace std;

int main()
{
	int H, W, res = 0;
	cin >> H >> W;
	vector<vector<int>> c(H, vector<int>(W)), dp(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> c[i][j];
			if (c[i][j] == 0) {
				dp[i][j] = 1;
				if (i - 1 >= 0 && j - 1 >= 0) {
					int d = min(dp[i - 1][j], dp[i][j - 1]);
					dp[i][j] = max(dp[i][j], d + (c[i - d][j - d] ? 0 : 1));
				}
				res = max(res, dp[i][j]);
			}
		}
	}
	cout << res * res << endl;
	return 0;
}