#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
const int MAXM = 1005;
int d[3010];
char s[MAXN][MAXM];
int n, m;
queue<int> q;
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  memset(d, -1, sizeof(d));
  int flag = n + m;
  d[n - 1] = 0;
  q.push(n - 1);
  while (!q.empty()) {
    int st = q.front();
    q.pop();
    if (st < flag) {
      for (j = 0; j < m; j++) {
        if (s[st][j] == '#' && d[flag + j] == -1) {
          d[flag + j] = d[st] + 1;
          q.push(flag + j);
        }
      }
    } else {
      st -= flag;
      for (i = 0; i < n; i++) {
        if (s[i][st] == '#' && d[i] == -1) {
          d[i] = d[st + flag] + 1;
          q.push(i);
        }
      }
    }
  }
  cout << d[0] << endl;
}
