#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> road(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.') {
        road[i][j] = true;
      } else {
        road[i][j] = false;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vector<vector<int>> cost(h, vector<int>(w, -1));
      int move[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
      queue<tuple<int, int, int>> next_go;
      next_go.push(make_tuple(i, j, 0));
      while (!next_go.empty()) {
        int x, y, c;
        tie(x, y, c) = next_go.front();
        next_go.pop();
        cost[x][y] = c;
        for (int k = 0; k < 4; k++) {
          int xx = x + move[k][0], yy = y + move[k][1];
          if (0 <= xx && xx < h && 0 <= yy && yy < w) {
            if (cost[xx][yy] == -1 && road[xx][yy]) {
              cost[xx][yy] = c + 1;
              next_go.push(make_tuple(xx, yy, c + 1));
            }
          }
        }
        ans = max(ans, c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
