#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  int h, w;
  for (int i = 0, i_len = int(H); i < i_len; ++i) {
    cin >> S[i];
    for (int j = 0, j_len = int(W); j < j_len; ++j)
      if (S[i][j] == '.') {
        h = i;
        w = j;
      }
  }
  int ans = 0;
  int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, 1, -1};
  bool change = true;
  while (change) {
    change = false;
    vector<vector<int>> d(H, vector<int>(W, -1));
    queue<pair<int, int>> que;
    que.push(pair<int, int>(h, w));
    d[h][w] = 0;
    while (!que.empty()) {
      pair<int, int> p = que.front();
      que.pop();
      int x = p.first, y = p.second;
      for (int j = 0, j_len = int(4); j < j_len; ++j) {
        int nx = x + dx[j], ny = y + dy[j];
        if (0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == '.' &&
            d[nx][ny] == -1) {
          que.push(pair<int, int>(nx, ny));
          d[nx][ny] = d[x][y] + 1;
          if (ans < d[nx][ny]) {
            ans = d[nx][ny];
            h = nx, w = ny;
            change = true;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
