#include <bits/stdc++.h>
using namespace std;
int n, m;
char mat[25][25];
int d1[25][25], d2[25][25];
bool u1[25][25], u2[25][25];
int dl[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
bool interior(int i, int j) { return i >= 1 && j >= 1 && i <= n && j <= m; }
void lee(int x, int y, int d[25][25], bool u[25][25]) {
  queue<pair<int, int> > q;
  d[x][y] = 0;
  q.push(make_pair(x, y));
  u[x][y] = true;
  while (!q.empty()) {
    auto act = q.front();
    q.pop();
    int i = act.first;
    int j = act.second;
    for (int k = 0; k < 4; ++k) {
      if (!interior(i + dl[k], j + dc[k])) {
        continue;
      }
      if (u[i + dl[k]][j + dc[k]]) {
        continue;
      }
      if (mat[i + dl[k]][j + dc[k]] != '.') {
        continue;
      }
      d[i + dl[k]][j + dc[k]] = d[i][j] + 1;
      u[i + dl[k]][j + dc[k]] = true;
      q.push(make_pair(i + dl[k], j + dc[k]));
    }
  }
}
int main() {
  cin >> n >> m;
  int xs, ys = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> mat[i][j];
      if (mat[i][j] == '.') {
        if (ys == -1) {
          xs = i, ys = j;
        }
      }
    }
  }
  lee(xs, ys, d1, u1);
  int maxx = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (d1[i][j] > maxx) {
        maxx = d1[i][j];
        xs = i, ys = j;
      }
    }
  }
  lee(xs, ys, d2, u2);
  maxx = -1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      maxx = max(maxx, d2[i][j]);
    }
  }
  cout << maxx << '\n';
  return 0;
}
