#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const long long limit = 2e9;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1, 1, 2, 2, 1, -1, -2, -2};
const int ky[] = {2, 2, 1, -1, -2, -2, -1, 1};
struct dsu {
  int parent[N];
  int cont;
  void make_set(int n) {
    for (int i = 1; i <= n; i++) parent[i] = i;
    cont = n;
  }
  int find_set(int v) {
    if (v == parent[v]) return v;
    return find_set(parent[v]);
  }
  void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
      parent[b] = a;
      cont--;
    }
  }
};
struct nod {
  int x, y, d;
  nod(int x_, int y_, int d_) {
    x = x_;
    y = y_;
    d = d_;
  }
  void set(int x_, int y_, int d_) {
    x = x_;
    y = y_;
    d = d_;
  };
};
char tab[25][25];
bool vis[25][25];
int n, m;
int nx, ny, nd;
bool ok(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
void bfs(int i, int j) {
  memset(vis, false, sizeof(vis));
  queue<nod> q;
  q.push(nod(i, j, 0));
  vis[i][j] = true;
  nod tmp(-1, -1, -1);
  while (!q.empty()) {
    int u = q.front().x;
    int v = q.front().y;
    int d = q.front().d;
    tmp.set(u, v, d);
    q.pop();
    for (int k = 0; k < 4; k++) {
      int a = u + dx[k];
      int b = v + dy[k];
      if (ok(a, b) && tab[a][b] == '.' && !vis[a][b]) {
        q.push(nod(a, b, d + 1));
        vis[a][b] = true;
      }
    }
  }
  nx = tmp.x;
  ny = tmp.y;
  nd = tmp.d;
}
int main() {
  int r, c;
  cin >> r >> c;
  n = r, m = c;
  int sx, sy, sd;
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      cin >> tab[i][j];
      if (tab[i][j] == '.') sx = i, sy = j;
    }
  }
  bfs(sx, sy);
  sx = nx;
  sy = ny;
  sd = nd;
  bfs(sx, sy);
  sx = nx;
  sy = ny;
  sd = nd;
  cout << sd;
  return 0;
}
