#include using namespace std; using ll=long long; using ld=long double; using P=pair; using V=vector; #define rep(i,n) for(ll i=0;i> h >> w; vector a(h,V(w)); rep(i,h) rep(j,w){ char c; cin >> c; a[i][j]=c-'a'; } string t; t+=(char)('a'+a[0][0]); set

s; s.insert(P(0,0)); while(t.size() b(0,V(3)); for(auto i=s.begin();i!=s.end();++i){ P p=*i; int x=p.first,y=p.second; if(x+1