#include <bits/stdc++.h>
using namespace std;
char s[22][22];
queue<pair<int, int> > q;
int ans = 1e9;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool used[22][22];
int step[22][22];
int main() {
  int h, k;
  cin >> h >> k;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < k; j++) cin >> s[i][j];
  q.push(make_pair(h - 1, 0));
  while (!q.empty()) {
    pair<int, int> x = q.front();
    q.pop();
    int a = x.first;
    int b = x.second;
    used[a][b] = true;
    if (a == 0 && b == k - 1) {
      ans = step[a][b];
      break;
    }
    for (int i = 0; i < 4; i++) {
      a += dx[i];
      b += dy[i];
      if (a >= 0 && a < h && b >= 0 && b < k && s[a][b] != '#' && !used[a][b]) {
        used[a][b] = true;
        step[a][b] = step[a - dx[i]][b - dy[i]] + 1;
        q.push(make_pair(a, b));
      }
      a -= dx[i];
      b -= dy[i];
    }
  }
  cout << ans << endl;
  return 0;
}
