#include <bits/stdc++.h>
using namespace std;
const int INF = 100;
int h, w;
char maze[21][21];
int d[21][21];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void solve() {
  queue<pair<int, int> > que;
  que.push(pair<int, int>(0, 0));
  d[0][0] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == h - 1 && p.second == w - 1) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny <= w && maze[nx][ny] == '.' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> maze[i][j];
      d[i][j] = INF;
    }
  }
  solve();
  cout << d[h - 1][w - 1] << endl;
  return 0;
}
