#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int h, w, ans = 0;
  cin >> h >> w;
  int x[4] = {1, -1, 0, 0};
  int y[4] = {0, 0, 1, -1};
  vector<vector<char>> vec(h, vector<char>(w));
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) cin >> vec[i][j];
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) {
      if (vec[i][h] == '#') continue;
      queue<pair<int, int>> q;
      if (!q.empty()) {
        cout << "eee" << endl;
      }
      pair<int, int> p(i, j);
      vector<vector<int>> vvv(h, vector<int>(w, -1));
      q.push(p);
      vvv[i][j] = 0;
      while (!q.empty()) {
        p = q.front();
        q.pop();
        for (int k = 0; k < (4); k++) {
          int xx = p.first + x[k], yy = p.second + y[k];
          if (xx < 0 || xx >= h || yy < 0 || yy >= w) continue;
          if (vec[xx][yy] == '.' && vvv[xx][yy] < 0) {
            pair<int, int> pp(xx, yy);
            q.push(pp);
            vvv[xx][yy] = vvv[p.first][p.second] + 1;
            ans = max(ans, vvv[xx][yy]);
          }
        }
      }
    }
  cout << ans << endl;
}
