#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[2000][2000];
int dp[2000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  queue<int> q;
  dp[n - 1] = 0;
  q.push(n - 1);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    if (t >= n) {
      t -= n;
      for (int i = 0; i < n; i++)
        if (a[i][t] == '#' && dp[i] == -1) {
          dp[i] = dp[t + n] + 1;
          q.push(i);
        }
    } else {
      for (int i = 0; i < m; i++)
        if (a[t][i] == '#' && dp[n + i] == -1) {
          dp[n + i] = dp[t] + 1;
          q.push(n + i);
        }
    }
  }
  cout << dp[0];
  return 0;
}
