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

int main() {
  int H, W;

  cin >> H >> W;
  vector<vector<int>> G(H+1, vector<int>(W+1, 0));
  vector<vector<bool>> stained(H+1, vector<bool>(W+1, false));

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      int isStained;
      cin >> isStained;
      if (isStained) stained[i][j] = true;
    }
  }

  int max = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (stained[i][j]) {
        G[i][j] = 0;
        continue;
      }
      int left = G[i][j-1];
      int left_up = G[i-1][j-1];
      int up = G[i-1][j];
      int minVal = min(left, min(left_up, up));

      G[i][j] = minVal + 1;
      if (G[i][j] > max) max = G[i][j];
    }
  }

  cout << max * max << endl;
  return 0;
}

