//注意点
//Tは3つの値を持つ構造
//だがワイルドカードとしても使っている
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
    initon() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.setf(ios::fixed);
        cout.precision(16);
        srand((unsigned) clock() + (unsigned) time(NULL));
    };
} __initon;

//@必須構造
struct T {
    int f, s, t;
    T() { f = -1, s = -1, t = -1; }
    T(int f, int s, int t) : f(f), s(s), t(t) {}
    bool operator<(const T &r) const {
        return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
        //return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
    }
    bool operator>(const T &r) const {
        return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
        //return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
    }
    int operator[](int i) {
        assert(i < 3);
        return i == 0 ? f : i == 1 ? s : t;
    }
};

//@マクロ省略系 型,構造

#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo= bool;
using P = pair<ll, ll>;
#define F first
#define fi first
#define S second
#define se second
#define vec vector
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==


//マクロ省略系 コンテナ
using vi = vector<int>;
#define vvi(a, b, c) vec<vi> a(b,vi(c))
using vb = vector<bool>;
#define vvb(a, b, c) vec<vb> a(b,vb(c))
using vs = vector<string>;
#define vvs(a, b, c) vec<vs> a(b,vs(c))
using vl = vector<ll>;
#define vvl(a, b, c) vec<vl> a(b,vl(c))
using vd = vector<double>;
#define vvd(a, b, c) vec<vd> a(b,vd(c))
using vc=vector<char>;
#define vvc(a, b, c) vec<vc> a(b,vc(c))
using vp = vector<P>;
#define vvp(a, b, c) vec<vp> a(b,vp(c))
using vt = vector<T>;
#define vvt(a, b, c) vec<vt> a(b,vt(c))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define PQ priority_queue<ll, vector<ll>, greater<ll> >
using seti = set<int>;
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define mmap multimap

//マクロ 繰り返し
#define _overloadrep(_1, _2, _3, name, ...) name
# define _rep(i, n) for(int i = 0,_lim=n; i < _lim ; i++)
#define repi(i, m, n) for(int i = m,_lim=n; i < _lim ; i++)
#define rep(...) _overloadrep(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rer(i, n) for(int i = n; i >= 0 ; i--)
#define reri(i, m, n) for(int i = m,_lim=n; i >= _lim ; i--)
#define rer(...) _overloadrep(__VA_ARGS__,reri,_rer,)(__VA_ARGS__)
#define fora(a, b) for(auto&& a : b)
#define forg(gi, ve) if (ve.size())for (int gi = 0, f = ve[gi].from, t = ve[gi].to, c = ve[gi].cost; gi < ve.size(); gi++,f = ve[gi].from, t = ve[gi].to, c = ve[gi].cost)

//マクロ 定数
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int) 1e9 + 100;
const ll linf = (ll) 1e18 + 100;
const double eps = 1e-9;
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};

//マクロ省略形 関数等
#define arsz(a) (sizeof(a)/sizeof(a[0]))
#define s(a) (a.size())
#define rs(a) (a.resize())
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

//@拡張系 こう出来るべきというもの

//埋め込み 存在を意識せずに機能を増やされているもの
// 境界チェック付きvector
namespace std_vector_bounds_checking {
    using namespace std;
    template<class T, class A = std::allocator<T>> struct vector : std::vector<T, A> {
        using std::vector<T, A>::vector;
        typename std::vector<T>::reference operator[](typename std::vector<T>::size_type n) {
            return this->at(n);
        }
    };
}
namespace std {
    template<> class hash<std::pair<signed, signed>> {
    public:
        size_t operator()(const std::pair<signed, signed> &x) const {
            return hash<ll>()(((ll) x.first << 32) + x.second);
        }
    };
    template<> class hash<std::pair<ll, ll>> {
    public:
        size_t operator()(const std::pair<ll, ll> &x) const {
            return hash<ll>()(((ll) x.first << 32) + x.second);
        }
    };
}
istream &operator>>(istream &iss, P &a) {
    iss >> a.first >> a.second;
    return iss;
}
template<typename T> istream &operator>>(istream &iss, vector<T> &vec) {
    for (T &x: vec) iss >> x;
    return iss;
}
template<typename T> ostream &operator<<(ostream &os, vector <T> &vec) {
    for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
template<typename V, typename H> void resize(vector<V> &vec, const H head) {  //再帰の終端。 可変長templateの長さが 0 になるとこっちが呼ばれる。
    vec.resize(head);
}
template<typename V, typename H, typename ... T> void resize(vector<V> &vec, const H &head, const T ... tail) {
    vec.resize(head);
    for (auto &v: vec) resize(v, tail...);
}
template<class T> T pop(set<T> &set) {
    T res = *set.begin();
    set.erase(set.find(res));
    return res;
}
template<class T> T pop(mset<T> &set) {
    T res = *set.begin();
    set.erase(set.find(res));
    return res;
}
template<class T> T popBack(set<T> &set) {
    T res = *set.rbegin();
    set.erase(set.find(res));
    return res;
}
template<class T> T popBack(mset<T> &set) {
    T res = *set.rbegin();
    set.erase(set.find(res));
    return res;
}
template<class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template<class T> inline void rsort(vector<T> &a) { sort(a.begin(), a.end(), greater<T>()); };
template<class T> inline void sort(vector<T> &a, int len) { sort(a.begin(), a.begin() + len); };
template<class T> inline void rsort(vector<T> &a, int len) { sort(a.begin(), a.begin() + len, greater<T>()); };
template<class U> inline void sortp(vector<U> &a, vector<U> &b) {
    vp c;
    int n = s(a);
    assert(n == s(b));
    rep(i, n)c.eb(a[i], b[i]);
    sort(c);
    rep(i, n) {
        a[i] = c[i].first;
        b[i] = c[i].second;
    }
};
template<class U> inline void rsortp(vector<U> &a, vector<U> &b) {
    vp c;
    int n = s(a);
    assert(n == s(b));
    rep(i, n)c.eb(a[i], b[i]);
    rsort(c);
    rep(i, n) {
        a[i] = c[i].first;
        b[i] = c[i].second;
    }
};

int n, k, d, H, W, x, y, z, q;
int cou;
string s;
vi a, b, c;
vvi (S, 0, 0);
vp p;

void solve(int n_, vi a_) {
    cin >> H >> W;
    resize(S, H, W);
    cin >> S;
    vvi (dp, H, W);
    int res=0;

    rep(h, H) {
        rep(w, W) {
            if (S[h][w] == 1)continue;
            if (h == 0 || w == 0)dp[h][w] = 1;
            else {
                dp[h][w] = inf;
                dp[h][w] = min(dp[h][w], dp[h - 1][w] + 1);
                dp[h][w] = min(dp[h][w], dp[h][w - 1] + 1);
                dp[h][w] = min(dp[h][w], dp[h - 1][w - 1] + 1);
            }
            res=max(dp[h][w],res);
        }
    }
    cout << max(0ll, res*res) << endl;
}

int sister(int n, vi a) {
    return 0;
}

signed main() {
    solve(0, vi(1));
//    cin >> n;
//    addn(a, n);
//    cout << solve(n, m, a) << endl;
//    cout << sister(n, m, a) << endl;
//    
    return 0;
};



Measured memory_bytes: 33764