#include <bits/stdc++.h>
using namespace std;
bool vis[105][105];
long long int e1, e2, h, w, dp[105][105];
void bfs(long long int i1, long long int j1, long long int dep) {
  vis[i1][j1] = 1;
  pair<long long int, long long int> p;
  queue<pair<long long int, long long int>> Q;
  Q.push({i1, j1});
  while (!Q.empty()) {
    long long int i = Q.front().first;
    long long int j = Q.front().second;
    Q.pop();
    if (i < h && !vis[i + 1][j]) {
      Q.push({i + 1, j});
      vis[i + 1][j] = 1;
      dp[i + 1][j] = dp[i][j] + 1;
      e1 = i + 1;
      e2 = j;
    }
    if (i > 1 && !vis[i - 1][j]) {
      Q.push({i - 1, j});
      vis[i - 1][j] = 1;
      dp[i - 1][j] = dp[i][j] + 1;
      e1 = i - 1;
      e2 = j;
    }
    if (j < w && !vis[i][j + 1]) {
      Q.push({i, j + 1});
      vis[i][j + 1] = 1;
      dp[i][j + 1] = dp[i][j] + 1;
      e1 = i;
      e2 = j + 1;
    }
    if (j > 1 && !vis[i][j - 1]) {
      Q.push({i, j - 1});
      vis[i][j - 1] = 1;
      dp[i][j - 1] = dp[i][j] + 1;
      e1 = i;
      e2 = j - 1;
    }
  }
}
int main() {
  long long int i, j, si, sj, flag = 0;
  char S[25][25];
  cin >> h >> w;
  for (i = 1; i <= h; i++)
    for (j = 1; j <= w; j++) cin >> S[i][j];
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (S[i][j] == '.' && flag == 0) {
        si = i, sj = j;
        flag = 1;
      }
      if (S[i][j] == '#') {
        vis[i][j] = 1;
      }
    }
  }
  e1 = si;
  e2 = sj;
  bfs(si, sj, 0);
  memset(vis, 0, sizeof(vis));
  memset(dp, 0, sizeof(dp));
  for (i = 1; i <= h; i++) {
    for (j = 1; j <= w; j++) {
      if (S[i][j] == '#') {
        vis[i][j] = 1;
      }
    }
  }
  bfs(e1, e2, 0);
  cout << dp[e1][e2] << "\n";
  return 0;
}
