#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
char data[22][22];
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int h, w;
pair<int, int> bfs(vector<vector<int> > &res, int sx, int sy) {
  queue<pair<int, int> > que;
  res[sx][sy] = 0;
  que.push(pair<int, int>(sx, sy));
  while (!que.empty()) {
    pair<int, int> current = que.front();
    que.pop();
    int cx = current.first;
    int cy = current.second;
    int cc = res[cx][cy];
    for (int i = 0; i < 4; ++i) {
      int nx = cx + dx[i];
      int ny = cy + dy[i];
      if (data[nx][ny] != '#' && res[nx][ny] == INF) {
        res[nx][ny] = cc + 1;
        que.push(pair<int, int>(nx, ny));
      }
    }
  }
  int ma = 0;
  pair<int, int> mp;
  for (int i = 0; i < 22; ++i) {
    for (int j = 0; j < 22; ++j) {
      if (res[i][j] != INF && res[i][j] > ma) {
        ma = res[i][j];
        mp = pair<int, int>(i, j);
      }
    }
  }
  return mp;
}
int main() {
  cin >> h >> w;
  int sx, sy;
  vector<int> infs(22, INF);
  vector<vector<int> > res(22, infs);
  vector<vector<int> > res2(22, infs);
  for (int i = 0; i < 22; ++i) {
    for (int j = 0; j < 22; ++j) {
      data[i][j] = '#';
      res[i][j] = res2[i][j] = INF;
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      cin >> data[j][i];
      if (data[j][i] == '.') {
        sx = j;
        sy = i;
      }
    }
  }
  pair<int, int> np = bfs(res, sx, sy);
  pair<int, int> rp = bfs(res2, np.first, np.second);
  cout << res2[rp.first][rp.second] << endl;
  ;
  return 0;
}
