H,W=map(int,input().split()) L=list() for i in range(H): s=input() L.append(s) ans=list() ans.append(L[0][0]) A=[0,0] def f(x,y): if 0<=x