#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
  int h, w; cin >> h >> w;
  int c[h+1][w+1];
  //dp[i][j] means the length of maximum square using (i, j)
  int dp[h+1][w+1];
  int maxSq=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> c[i][j];
    }
  }
  //initialize dp
  for(int i=0;i<=h;i++) dp[i][0]=0;
  for(int i=0;i<=w;i++) dp[0][i]=0;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(c[i][j] == 1) dp[i][j]=0;
      else{
        dp[i][j]=min(dp[i-1][j-1], min(dp[i-1][j], dp[i][j-1]))+1;
        maxSq=max(maxSq, dp[i][j]);
      }
    }
  }
  cout << maxSq*maxSq << endl;
}