#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int H, W;
	scanf("%d %d", &H, &W);

	int A[H + 1][W + 1];
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			scanf("%d", &A[i][j]);
		}
	}
	int G[H + 1][W + 1];
	for (int i = 0; i <= H; ++i) {
		G[i][0] = 0;
	}
	for (int i = 0; i <= W; ++i) {
		G[0][i] = 0;
	}

	int maxWidth = 0;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (A[i][j] == 1) {
				G[i][j] = 0;
			} else {
				G[i][j] = min(G[i][j - 1], min(G[i - 1][j - 1], G[i - 1][j])) + 1;
			}
			maxWidth = max(maxWidth, G[i][j]);
		}
	}
	cout << maxWidth * maxWidth << endl;
	return 0;
}