#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  queue<pair<int, int>> que;
  vector<pair<int, int>> move = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
  vector<vector<int>> ans(h, vector<int>(w, 0));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      vector<vector<int>> distance(h, vector<int>(w, 0));
      vector<vector<bool>> been(h, vector<bool>(w, 0));
      que.push({i, j});
      while (!que.empty()) {
        int beforeh = que.front().first;
        int beforew = que.front().second;
        que.pop();
        for (int k = 0; k < 4; k++) {
          int nowh = beforeh + move[k].first;
          int noww = beforew + move[k].second;
          if (nowh >= 0 && noww >= 0 && nowh < h && noww < w) {
            if (been[nowh][noww]) continue;
            if (s[nowh][noww] == '#') continue;
            been[nowh][noww] = true;
            que.push({nowh, noww});
            distance[nowh][noww] = distance[beforeh][beforew] + 1;
          }
        }
      }
      for (int nowi = 0; nowi < h; nowi++)
        for (int nowj = 0; nowj < w; nowj++)
          ans[nowi][nowj] = max(ans[nowi][nowj], distance[nowi][nowj]);
    }
  }
  int longest = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) longest = max(longest, ans[i][j]);
  cout << longest << endl;
}
