#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long bfs(int h, int w, queue<pair<int, int>>& q, int maze[20][20]) {
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    int r = p.first;
    int c = p.second;
    int current = maze[r][c];
    if (r == 0 && c == w - 1) {
      return current;
    }
    if (r > 0 && maze[r - 1][c] == '.') {
      maze[r - 1][c] = current + 1;
      q.push(pair<int, int>(r - 1, c));
    }
    if (r < h - 1 && maze[r + 1][c] == '.') {
      maze[r + 1][c] = current + 1;
      q.push(pair<int, int>(r + 1, c));
    }
    if (c > 0 && maze[r][c - 1] == '.') {
      maze[r][c - 1] = current + 1;
      q.push(pair<int, int>(r, c - 1));
    }
    if (c < w - 1 && maze[r][c + 1] == '.') {
      maze[r][c + 1] = current + 1;
      q.push(pair<int, int>(r, c + 1));
    }
  }
}
int main(int argc, char** argv) {
  int h, w;
  int maze[20][20] = {};
  string line;
  cin >> h >> w;
  for (int i = 0; i < (h); i++) {
    cin >> line;
    for (int j = 0; j < (w); j++) {
      maze[i][j] = line.at(j);
    }
  }
  int r = h - 1;
  int c = 0;
  queue<pair<int, int>> q;
  q.push(pair<int, int>(r, c));
  maze[r][c] = 0;
  long long ans = bfs(h, w, q, maze);
  cout << ans << endl;
  return 0;
}
