#include #include using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) using mint = atcoder::modint1000000007; int main(){ int h,w; cin>>h>>w; vector> a(h,vector(w)); rep(i,h) rep(j,w) cin>>a.at(i).at(j); vector dx={-1,-1,0,1,1,1}; vector dy={0,1,1,1,0,-1}; auto isok=[&](int x,int y){ return 0<=x&&x=h) y1=ch1-h+1; else x1=ch1; rep(i1,6){ ll tmp=select(x1,y1,i1); if(ans