#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void) {
  int h, w;
  cin >> h >> w;
  const int INF = 1e9;
  vector<vector<int>> dist(h, vector<int>(w, INF));
  vector<string> s(h);
  for (int i = 0; i < (h); i++) cin >> s[i];
  queue<pair<int, int>> pp;
  int ans = 0;
  int di[4] = {-1, 1, 0, 0};
  int dj[4] = {0, 0, -1, 1};
  for (int l = 0; l < (h); l++) {
    for (int k = 0; k < (w); k++) {
      for (int i = 0; i < (h); i++)
        for (int j = 0; j < (w); j++) dist[i][j] = INF;
      dist[l][k] = 0;
      pp.push(make_pair(l, k));
      while (!pp.empty()) {
        pair<int, int> v = pp.front();
        pp.pop();
        for (int i = 0; i < (4); i++) {
          pair<int, int> vxy = make_pair(v.first + di[i], v.second + dj[i]);
          if (vxy.first < 0 || vxy.second < 0) continue;
          if (vxy.first > h - 1 || vxy.second > w - 1) continue;
          if (s[vxy.first][vxy.second] == '#') continue;
          if (dist[vxy.first][vxy.second] != INF) continue;
          dist[vxy.first][vxy.second] = dist[v.first][v.second] + 1;
          pp.push(make_pair(vxy.first, vxy.second));
        }
      }
      for (int i = 0; i < (h); i++) {
        for (int j = 0; j < (w); j++) {
          if (dist[i][j] == INF) continue;
          if (ans < dist[i][j]) ans = dist[i][j];
        }
      }
    }
  }
  cout << ans << endl;
}
