#include <bits/stdc++.h>
using namespace std;
int vis[30][30] = {};
char a[30][30] = {};
int st[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
struct s {
  int x, y, cnt;
} no, ne, an;
queue<s> q;
int n, m, i;
int main() {
  int anso, anst;
  int bfs();
  while (~scanf("%d%d", &n, &m)) {
    for (i = 0; i < n; i++) scanf("%s", a[i]);
    no.x = 0;
    no.y = 0;
    no.cnt = 0;
    an.x = n - 1;
    an.y = m - 1;
    anso = bfs();
    memset(vis, 0, sizeof(vis));
    while (!q.empty()) q.pop();
    no.x = n - 1;
    no.y = 0;
    no.cnt = 0;
    an.x = 0;
    an.y = m - 1;
    anst = bfs();
    if (anst > anso)
      printf("%d\n", anst);
    else
      printf("%d\n", anso);
    memset(a, 0, sizeof(a));
    memset(vis, 0, sizeof(vis));
    while (!q.empty()) q.pop();
  }
}
int bfs() {
  int ans;
  q.push(no);
  vis[no.x][no.y] = 1;
  while (!q.empty()) {
    no = q.front();
    if (no.x == an.x && no.y == an.y) {
      ans = no.cnt;
      return ans;
    }
    for (i = 0; i < 4; i++) {
      ne.x = no.x + st[i][0];
      ne.y = no.y + st[i][1];
      ne.cnt = no.cnt + 1;
      if (ne.x < 0 || ne.y < 0 || ne.x >= n || ne.y >= m || vis[ne.x][ne.y] ||
          a[ne.x][ne.y] == '#')
        continue;
      vis[ne.x][ne.y] = 1;
      q.push(ne);
    }
    q.pop();
  }
}
