#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int mod = 31;
void solve();
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
int used0[1111];
int ans[1111][3];
int used1[1111];
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(used0, 0, sizeof used0);
  queue<pair<int, int> > que;
  que.push(make_pair(0, 0));
  used0[0] = true;
  ans[0][0] = 0;
  while (que.size()) {
    pair<int, int> cur = que.front();
    que.pop();
    if (cur.second) {
      for (int i = 0; i < n; i++) {
        if (a[i][cur.first] == '#' && !used0[i]) {
          used0[i] = true;
          ans[i][0] = ans[cur.first][cur.second] + 1;
          que.push(make_pair(i, 0));
        }
      }
    } else {
      for (int i = 0; i < m; i++) {
        if (a[cur.first][i] == '#' && !used1[i]) {
          used1[i] = true;
          ans[i][1] = ans[cur.first][cur.second] + 1;
          que.push(make_pair(i, 1));
        }
      }
    }
  }
  if (ans[n - 1][0] == 0)
    printf("-1");
  else
    printf("%d", ans[n - 1][0]);
}
