#include <bits/stdc++.h>
int _cer;
using namespace std;
vector<int> v[2003];
int n, m;
char ch[1003];
int dis[2003];
int q[10004], l, r = 1;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", ch);
    for (int j = 0; j < m; ++j) {
      if (ch[j] == '#') {
        v[i].push_back(n + j);
        v[n + j].push_back(i);
      }
    }
  }
  q[0] = n - 1;
  dis[n - 1] = 1;
  while (l < r) {
    int cur = q[l++];
    for (int i = 0; i < v[cur].size(); ++i) {
      if (!dis[v[cur][i]]) {
        q[r++] = v[cur][i];
        dis[v[cur][i]] = dis[cur] + 1;
      }
    }
  }
  printf("%d\n", dis[0] - 1);
  return 0;
}
