#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
int n, m;
vector<int> g[maxn];
queue<int> q;
int dp[maxn];
void bfs() {
  memset(dp, -1, sizeof(dp));
  q.push(n);
  dp[n] = 0;
  while (!q.empty()) {
    int v = q.front();
    for (auto i : g[v]) {
      if (dp[i] == -1) {
        dp[i] = dp[v] + 1;
        q.push(i);
      }
    }
    q.pop();
  }
}
void sol() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      char x;
      cin >> x;
      if (x == '#') {
        g[i].push_back(j + n);
        g[j + n].push_back(i);
      }
    }
  }
  bfs();
  cout << dp[1] << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  while (t--) {
    sol();
  }
  return 0;
}
