#include <bits/stdc++.h>
using namespace std;
int getLargestSquare(int H, int W, int G[1400][1400]) {
  int dp[1400][1400];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      dp[i][j] = (G[i][j] + 1) % 2;
    }
  }
  int maxWidth = 0;
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      if (G[i][j]) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
        maxWidth = max(maxWidth, dp[i][j]);
      }
    }
  }
  return maxWidth * maxWidth;
}
int main() {
  int H, W, G[1400][1400];
  scanf("%d %d", &H, &W);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) scanf("%d", &G[i][j]);
  }
  printf("%d\n", getLargestSquare(H, W, G));
  return 0;
}
