#include <bits/stdc++.h>
using namespace std;
long long mp[21][21];
long long mp1[21][21];
const long long inf = 123456789;
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < 21; i++)
    for (int j = 0; j < 21; j++) mp[i][j] = inf;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '#') {
        mp[i][j] = 1234567891011;
        mp1[i][j] = 1234567891011;
      }
    }
  }
  queue<pair<long long, long long> > que;
  mp[0][0] = 0;
  que.push(pair<long long, long long>(0, 0));
  int dx[4] = {0, 0, -1, 1};
  int dy[4] = {1, -1, 0, 0};
  for (int i = 0; i < 21; i++)
    for (int j = 0; j < 21; j++) mp1[i][j] = inf;
  while (que.size()) {
    pair<long long, long long> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      long long tx = p.second + dx[i];
      long long ty = p.first + dy[i];
      if (tx >= 0 && ty >= 0 && tx < w && ty < h && mp[ty][tx] == inf) {
        mp[ty][tx] = mp[p.first][p.second] + 1;
        que.push(pair<long long, long long>(ty, tx));
      }
    }
  }
  long long an = mp[h - 1][w - 1];
  queue<pair<long long, long long> > qu;
  qu.push(pair<long long, long long>(0, w - 1));
  mp1[0][w - 1] = 0;
  while (qu.size()) {
    pair<long long, long long> p = qu.front();
    qu.pop();
    for (int i = 0; i < 4; i++) {
      int tx = p.second + dx[i];
      int ty = p.first + dy[i];
      cout << "(" << ty << "," << tx << ")\n";
      {
        mp1[ty][tx] = mp1[p.first][p.second] + 1;
        qu.push(pair<long long, long long>(ty, tx));
      }
      if (tx >= 0 && ty >= 0 && tx < w && ty < h) {
        cout << mp1[ty][tx] << endl;
      }
    }
  }
  long long ans = mp1[h - 1][0];
  cout << max(ans, an) << endl;
  return 0;
}
