#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  int ans = 0;
  vector<vector<bool>> meiro(h, vector<bool>(w, false));
  for (int i = 0; i < h; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < w; j++) {
      if (str[j] == '.') meiro[i][j] = true;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!meiro[i][j]) continue;
      vector<vector<int>> cost(h, vector<int>(w, -1));
      queue<pair<int, int>> que;
      int ans_tmp = 0;
      cost[i][j] = 0;
      que.push(pair<int, int>(i, j));
      pair<int, int> P;
      int dx[4] = {-1, 1, 0, 0};
      int dy[4] = {0, 0, -1, 1};
      while (!que.empty()) {
        P = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          int new_y = P.first + dy[k];
          int new_x = P.second + dx[k];
          if (new_x < 0 || new_x >= w || new_y < 0 || new_y >= h) continue;
          if (cost[new_y][new_x] != -1) continue;
          if (!meiro[new_y][new_x]) continue;
          cost[new_y][new_x] = cost[P.first][P.second] + 1;
          que.push(pair<int, int>(new_y, new_x));
        }
      }
      for (int l = 0; l < h; l++) {
        for (int m = 0; m < w; m++) {
          ans = max(ans, cost[l][m]);
        }
      }
    }
    cout << ans << endl;
    return 0;
  }
}
