#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long maxn = (long long)5000;
const long double EPS = 1e-9;
const long long INF = (long long)1e18 + 18;
const long long MOD = (long long)1e9 + 7;
long long n, m, add = 2000, used[maxn], level[maxn];
string in;
vector<long long> g[maxn];
long long solve(long long s, long long d) {
  level[s] = 0;
  used[s] = 1;
  queue<long long> Q;
  Q.push(s);
  while (!Q.empty()) {
    long long top = Q.front();
    Q.pop();
    for (auto v : g[top]) {
      if (used[v]) continue;
      used[v] = 1;
      level[v] = level[top] + 1;
      Q.push(v);
    }
  }
  return level[d];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> in;
    for (long long j = 0; j < m; j++) {
      if (in[j] == '#') {
        g[i].push_back(j + add);
        g[j + add].push_back(i);
      }
    }
  }
  memset(used, 0, sizeof used);
  ;
  memset(level, -1, sizeof level);
  ;
  cout << solve(n - 1, 0) << endl;
  return 0;
}
