#include <bits/stdc++.h>
using namespace std;
const int INF = 4000;
int main() {
  int h, w;
  cin >> h >> w;
  char maz[h][w];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> maz[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (maz[i][j] == '#') break;
      vector<vector<int>> dif(h, vector<int>(w, INF));
      dif.at(i).at(j) = 0;
      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        int x, y;
        x = que.front().first;
        y = que.front().second;
        if (x - 1 >= 0 && maz[x - 1][y] == '.' && dif[x - 1][y] == INF) {
          que.push(make_pair(x - 1, y));
          dif[x - 1][y] = dif[x][y] + 1;
        }
        if (y - 1 >= 0 && maz[x][y - 1] == '.' && dif[x][y - 1] == INF) {
          que.push(make_pair(x, y - 1));
          dif[x][y - 1] = dif[x][y] + 1;
        }
        if (x + 1 < h && maz[x + 1][y] == '.' && dif[x + 1][y] == INF) {
          que.push(make_pair(x + 1, y));
          dif[x + 1][y] = dif[x][y] + 1;
        }
        if (y + 1 < w && maz[x][y + 1] == '.' && dif[x][y + 1] == INF) {
          que.push(make_pair(x, y + 1));
          dif[x][y + 1] = dif[x][y] + 1;
        }
        ans = max(ans, dif[x][y]);
        que.pop();
      }
    }
  }
  cout << ans << endl;
}
