#include <bits/stdc++.h>
using namespace std;
char G[44][44];
int visit[44][44] = {0};
int h, w;
int inbound(int i, int j) { return i > 0 && j > 0 && i <= h && j <= w; }
int a[4][2] = {0, 1, -1, 0, 0, -1, 1, 0};
int solve() {
  queue<int> qq;
  queue<int> qq2;
  queue<int> qq3;
  qq.push(h);
  qq2.push(1);
  qq3.push(0);
  visit[h][1] = 1;
  while (!qq.empty()) {
    int x = qq.front();
    int y = qq2.front();
    int len = qq3.front();
    if (x == 1 && y == w) return len;
    qq.pop();
    qq2.pop();
    qq3.pop();
    int x1 = x + 1;
    int y1 = y;
    if (inbound(x1, y1) && G[x1][y1] == '.' && !visit[x1][y1]) {
      visit[x1][y1] = 1;
      qq.push(x1);
      qq2.push(y1);
      qq3.push(len + 1);
    }
    x1 = x - 1;
    y1 = y;
    if (inbound(x1, y1) && G[x1][y1] == '.' && !visit[x1][y1]) {
      visit[x1][y1] = 1;
      qq.push(x1);
      qq2.push(y1);
      qq3.push(len + 1);
    }
    x1 = x;
    y1 = y - 1;
    if (inbound(x1, y1) && G[x1][y1] == '.' && !visit[x1][y1]) {
      visit[x1][y1] = 1;
      qq.push(x1);
      qq2.push(y1);
      qq3.push(len + 1);
    }
    x1 = x;
    y1 = y + 1;
    if (inbound(x1, y1) && G[x1][y1] == '.' && !visit[x1][y1]) {
      visit[x1][y1] = 1;
      qq.push(x1);
      qq2.push(y1);
      qq3.push(len + 1);
    }
  }
}
int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    cin >> G[i] + 1;
  }
  cout << solve() << endl;
  return 0;
}
