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

long long h, w;
vector<vector<long long>> c;

long long solve();

int main() {
  cin >> h >> w;
  c.assign(h, vector<long long>(w, 0));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      cin >> c[i][j];
      c[i][j] = 1 - c[i][j];
    }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (c[i][j]) {
        if (i != 0 && j != 0)
          c[i][j] = max(c[i][j],
                        min({c[i - 1][j], c[i][j - 1], c[i - 1][j - 1]}) + 1);
        res = max(res, c[i][j]);
      }
  return res * res;
}

