#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int h,w; cin>>h>>w; vector S(h); rep(i,h) cin>>S[i]; vector ans(h+w-1,'|'); ans[0]=S[0][0]; for(int k=1;k=w) continue; bool b=false; if(i>0 && S[i-1][j]==ans[k-1]) b=true; if(j>0 && S[i][j-1]==ans[k-1]) b=true; if(b==false) continue; if(S[i][j]