#include <iostream>
#include <vector>
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W));
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> a[i][j];
        }
    }
    vector<vector<int>> dp(H, vector<int>(W));
    int res = 0;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(a[i][j] == 1) {
                dp[i][j] = 0;
            } else if(i == 0 || j == 0) {
                dp[i][j] = 1;
            } else {
                dp[i][j] = min(dp[i-1][j], min(dp[i-1][j-1], dp[i][j-1])) + 1;
            }
            res = max(res, dp[i][j]);
        }
    }
    cout << res*res << endl;
}
