#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
vector<int> edges[MAXN];
queue<int> q;
int visited[MAXN];
int main() {
  int n, m, a, b;
  char x;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> x;
      if (x == '#') {
        edges[i].push_back(n + j);
        edges[n + j].push_back(i);
      }
    }
  }
  q.push(n - 1);
  q.push(0);
  while (!q.empty()) {
    a = q.front();
    q.pop();
    b = q.front();
    q.pop();
    if (a == 0) {
      cout << b;
      return 0;
    }
    for (int i : edges[a]) {
      if (!visited[i]) {
        q.push(i);
        q.push(b + 1);
        visited[i] = true;
      }
    }
  }
  cout << -1;
  return 0;
}
