#include <bits/stdc++.h>
using namespace std;
vector<int> a[2222];
int dis[2222];
int main() {
  for (int i = 0; i < 2222; ++i) dis[i] = -1;
  dis[0] = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      if (c == '#') a[i].push_back(n + j), a[n + j].push_back(i);
    }
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (int i = 0; i < a[p].size(); ++i)
      if (dis[a[p][i]] == -1) {
        q.push(a[p][i]);
        dis[a[p][i]] = dis[p] + 1;
      }
  }
  cout << dis[n - 1] << endl;
  return 0;
}
