#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e3 + 10;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
vector<long long> rc[2][MAXN];
long long h[2][MAXN];
int main() {
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= m; j++) {
      if (s[j - 1] == '#') {
        rc[0][i].push_back(j);
        rc[1][j].push_back(i);
      }
    }
  }
  long long cntt = 600, cntb = 600;
  queue<pair<long long, long long> > q;
  q.push(make_pair(n, 0));
  h[0][n] = 1;
  while (q.size()) {
    long long num = q.front().first, roc = q.front().second;
    for (auto u : rc[roc][num]) {
      if (!h[1 - roc][u]) {
        h[1 - roc][u] = h[roc][num] + 1;
        q.push(make_pair(u, 1 - roc));
      }
    }
    if (h[0][1]) {
      cout << h[0][1] - 1;
      return 0;
    }
    q.pop();
  }
  cout << -1;
  return 0;
}
