#include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #define mod 1000000007 #define INF 1000000000 #define LLINF 2000000000000000000LL #define MAX_L 5000000 #define SIZE 100001 int w,h; int m[100][100]; int mo[5]={0,1,0,-1,0}; bool visit[100][100]={0}; bool dfs(int y,int x,int by,int bx){ if(y<0 || x<0 || h<=y || w<=x) return false; if(visit[y][x]==true) return true; visit[y][x]=true; for(int i=0;i<4;i++){ if(y+mo[i]==by && x+mo[i+1]==bx) continue; if(m[y][x]==m[y+mo[i]][x+mo[i+1]]) if(dfs(y+mo[i],x+mo[i+1],y,x)){ return true; } } return false; } int main(){ scanf("%d%d",&w,&h); for(int i=0;i