#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = ";if(x==INF)cout<<"INF"<<endl;else cout<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

template<typename T> struct CumulativeSum2D
{
   vector<vector<T>> s;
   int m, n;
   CumulativeSum2D(const vector<vector<T>>& v) :
         m(v.size()), n(v[0].size()) {
      s.resize(m+1, vector<int>(n+1));
      for (int i = 0; i < m; i++) {
         for (int j = 0; j < n; j++) {
            s[i+1][j+1] = s[i+1][j] + v[i][j];
         }
      }
      for (int i = 0; i < m; i++) {
         for (int j = 0; j < n; j++) {
            s[i+1][j+1] += s[i][j+1];
         }
      }
   }
   int sum(int i, int j) const {
      return s[i+1][j+1];
   }
   int sum(int i, int j, int k, int l) const {
      return s[k+1][l+1] - s[i][l+1] - s[k+1][j] + s[i][j];
   }
};
bool check(const CumulativeSum2D<int>& s, int sz) {
   REP(i, s.m-sz+1) REP(j, s.n-sz+1) {
      if (s.sum(i,j,i+sz-1,j+sz-1) == 0) {
         return true;
      }
   }
   return false;
}
int binary_search(const CumulativeSum2D<int>& s, int MIN, int MAX)
{
   int m, l = MIN, r = MAX+1;
   while (r - l > 1) {
      m = (l + r) / 2;
      if (check(s, m)) {
         l = m;
      } else {
         r = m;
      }
   }
   return l;
}

signed main()
{
   int H, W; cin >> H >> W;
   V<V<int>> c(H, V<int>(W));
   REP(i, H) {
      REP(j, W) {
         cin >> c[i][j];
      }
   }
   CumulativeSum2D<int> s(c);

   int sz = binary_search(s, 0, min(H,W));
   cout << sz * sz << endl;

   return 0;
}



Measured memory_bytes: 33388