#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VL = vector<ll>;
const long long INF = 999999999;
struct P {
  ll x, y;
};
vector<string> ss;
ll H, W, d[21][21];
ll dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
bool used[23][23];
P bfs(ll s, ll t) {
  ll res = 0;
  P pres{s, t};
  for (int i = 0; i < 21; i++)
    for (int j = 0; j < 21; j++) d[i][j] = 0, used[i][j] = false;
  d[s][t] = 0;
  queue<P> que;
  que.push((P){s, t});
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      ll x = p.x, y = p.y, nx = p.x + dx[i], ny = p.y + dy[i];
      if (nx >= 0 && nx <= H - 1 && ny >= 0 && ny <= W - 1 &&
          ss[nx][ny] == '.' && !used[nx][ny]) {
        d[nx][ny] = d[x][y] + 1;
        used[nx][ny] = true;
        que.push((P){nx, ny});
        if (res < d[nx][ny]) {
          pres.x = nx;
          pres.y = ny;
        }
      }
    }
  }
  return pres;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string str;
    cin >> str;
    ss.push_back(str);
  }
  bool flag = false;
  ll x, y;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++)
      if (ss[i][j] == '.') {
        flag = true;
        x = i;
        y = j;
        break;
      }
    if (flag) break;
  }
  P c = bfs(x, y);
  P nc = bfs(c.x, c.y);
  cout << d[nc.x][nc.y] << endl;
}
