#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {-1, 0, 1, 0};
const vector<int> dy = {0, 1, 0, -1};
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; ++i) {
    cin >> grid[i];
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      pair<int, int> start = make_pair(i, j);
      for (int k = 0; k < h; ++k) {
        for (int l = 0; l < w; ++l) {
          pair<int, int> goal = make_pair(k, l);
          queue<pair<int, int>> q;
          vector<vector<int>> dist(h, vector<int>(w, -1));
          dist[start.first][start.second] = 0;
          q.push(start);
          while (!q.empty()) {
            pair<int, int> v = q.front();
            q.pop();
            for (int m = 0; m < 4; ++m) {
              pair<int, int> nv = make_pair(v.first + dx[m], v.second + dy[m]);
              if (nv.first < 0 or nv.first >= h or nv.second < 0 or
                  nv.second >= w)
                continue;
              if (grid[nv.first][nv.second] == '#') continue;
              if (dist[nv.first][nv.second] != -1) continue;
              dist[nv.first][nv.second] = dist[v.first][v.second] + 1;
              q.push(make_pair(nv.first, nv.second));
            }
          }
          ans = max(ans, dist[goal.first][goal.second]);
        }
      }
    }
  }
  cout << ans << endl;
}
