H,W=map(int,input().split()) MAP=[list(input()) for i in range(H)] R=[[1<<30]*W for i in range(H)] R[0][0]=0 for x in range(H): for y in range(W): for z,w in [[x+1,y],[x,y+1]]: if 0<=z<H and 0<=w<W: if MAP[z][w]==".": R[z][w]=min(R[z][w],R[x][y]) else: R[z][w]=min(R[z][w],R[x][y]+z+w) print(H+W-2+R[-1][-1])