#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int ans = 0;
  int r, c, sx, sy, gx, gy;
  cin >> r >> c;
  vector<string> s(r);
  for (int i = 0; i < r; ++i) {
    cin >> s[i];
  }
  for (int g = 0; g < r; g++) {
    for (int h = 0; h < c; h++) {
      sx = g;
      sy = h;
      int dist[51][51];
      fill((int*)dist, (int*)(dist + c), INF);
      queue<pair<int, int> > que;
      dist[sx][sy] = 0;
      que.push(pair<int, int>(sx, sy));
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        int x = p.first;
        int y = p.second;
        for (int i = 0; i < 4; ++i) {
          int nx = x + dx[i], ny = y + dy[i];
          if (nx < 0 || nx >= r || ny < 0 || ny >= c) continue;
          if (s[nx][ny] == '#') continue;
          if (dist[nx][ny] > dist[x][y] + 1) {
            dist[nx][ny] = dist[x][y] + 1;
            que.push(pair<int, int>(nx, ny));
          }
        }
      }
      for (int q = 0; q < (int)(r); q++) {
        for (int e = 0; e < (int)(c); e++) {
          if (dist[q][e] == INF) continue;
          ans = max(ans, dist[q][e]);
        }
      }
    }
  }
  cout << ans << endl;
}
