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

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> s(h, vector<int>(w));
	vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}
	
	for (int i = 0; i < h; i++) dp[i][0] = (s[i][0] ^ 1);
	for (int i = 0; i < w; i++) dp[0][i] = (s[0][i] ^ 1);
	
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (s[i][j]) continue;
			int val = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]});
			dp[i][j] = max(dp[i][j], val + 1);
		}
	}
	
	int ans = 0;
	for (vector<int> &v : dp) {
		ans = max(ans, *max_element(v.begin(), v.end()));
	}
	
	cout << ans * ans << '\n';
	
	return 0;
}
