#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
using route = pair<P, int>;
int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) cin >> S[i][j];
  int ans = 0;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      if (S[i][j] == '#') continue;
      P sp = P(i, j);
      for (int k = 0; k < (H); ++k)
        for (int l = 0; l < (W); ++l) {
          if (S[k][l] == '#') continue;
          P gp = P(k, l);
          if (sp == gp) continue;
          queue<route> q;
          q.push(route(sp, 0));
          map<P, bool> visited;
          int steps = INF;
          while (!q.empty()) {
            route r = q.front();
            q.pop();
            P p = r.first;
            if (p.first < 0 || p.first >= H || p.second < 0 || p.second >= W)
              continue;
            if (p == gp) {
              steps = min(steps, r.second);
              continue;
            }
            if (S[p.first][p.second] == '#' || visited[p] == true) continue;
            visited[p] = true;
            q.push(route(P(p.first + 1, p.second), r.second + 1));
            q.push(route(P(p.first - 1, p.second), r.second + 1));
            q.push(route(P(p.first, p.second + 1), r.second + 1));
            q.push(route(P(p.first, p.second - 1), r.second + 1));
          }
          ans = max(ans, steps);
        }
    }
  cout << ans << endl;
  return 0;
}
