#include <bits/stdc++.h>
using namespace std;
const int inf = 1010001000;
const long long INF = 1001000100010001000;
const int mod = (int)1e9 + 7;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (h); ++i) {
    cin >> s.at(i);
  }
  int ans = 0;
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      if (s.at(i).at(j) == '#') continue;
      int ma = 0;
      vector<vector<int>> d(h, vector<int>(w, -1));
      d[i][j] = 0;
      queue<pair<int, int>> q;
      q.push({i, j});
      while (!q.empty()) {
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        vector<int> dy = {0, 0, -1, 1};
        vector<int> dx = {1, -1, 0, 0};
        for (int k = 0; k < (4); ++k) {
          int ny = y + dy.at(k);
          int nx = x + dx.at(k);
          if (ny < 0 or h <= ny or nx < 0 or w <= nx) continue;
          if (s.at(ny).at(nx) == '#') continue;
          if (d.at(ny).at(nx) != -1) continue;
          d.at(ny).at(nx) = d.at(y).at(x) + 1;
          q.push({ny, nx});
          ma = max(ma, d.at(ny).at(x));
        }
      }
      ans = max(ans, ma);
    }
  }
  cout << ans << endl;
  return 0;
}
