Record
#include<bits/stdc++.h>
using namespace std;
const int xf[5] = {1,1,-1,-1},yf[5] = {1,-1,1,-1};
const int xf2[5] = {1,1,0,0},yf2[5] = {1,0,1,0};
const int typef[5] = {1,0,0,1};
int a[510][510] = {0},n,m;
int sp[501][501] = {0};
char ty;
bool check(int x,int y){
return x>=0 and x<=n and y>=0 and y<=m;
}
void bfs(){
list<int>x;
list<int>y;
x.push_front(0);
y.push_front(0);
sp[0][0] = 1;
while(!x.empty()){
int uix = x.front();
int uiy = y.front();
x.pop_front();
y.pop_front();
for(int k = 0;k<4;k++){
int xnew = uix+xf[k];
int ynew = uiy+yf[k];
if(sp[xnew][ynew] or !check(xnew,ynew))continue;
if(a[uix+xf2[k]][uiy+yf2[k]]==typef[k]){
x.push_front(xnew);
y.push_front(ynew);
sp[xnew][ynew] = sp[uix][uiy];
}else{
x.push_back(xnew);
y.push_back(ynew);
sp[xnew][ynew] = sp[uix][uiy]+1;
}
}
}
return;
}
int main(){
cin>>n>>m;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>ty;
a[i][j] = (ty=='/');
a[i][j] = (a[i][j]==0);
}
}
if((m+n)%2){
cout<<"NO SOLUTION"<<endl;
return 0;
}
bfs();
cout<<sp[n][m]-1<<endl;
return 0;
}