#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  long long h, w;
  cin >> h >> w;
  char s[30][30];
  for (int i = 0; i < h; i++) {
    string t;
    cin >> t;
    for (int j = 0; j < w; j++) {
      s[i][j] = t[j];
    }
  }
  long long ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      long long d[30][30];
      for (int x = 0; x < h; x++)
        for (int y = 0; y < w; y++) {
          d[x][y] = INF;
        }
      d[i][j] = 0;
      queue<pair<long long, long long> > que;
      que.push(pair<long long, long long>(i, j));
      while (!que.empty()) {
        pair<long long, long long> v = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          long long nx = v.first + dx[k], ny = v.second + dy[k];
          if (!(0 <= nx && nx < h && 0 <= ny && ny < w)) continue;
          if (s[nx][ny] == '#' || d[nx][ny] != INF) continue;
          d[nx][ny] = d[v.first][v.second] + 1;
          que.push(pair<long long, long long>(nx, ny));
        }
      }
      for (int x = 0; x < h; x++)
        for (int y = 0; y < w; y++) {
          if (d[x][y] == INF) continue;
          ans = max(ans, d[x][y]);
        }
    }
  cout << ans << endl;
  return 0;
}
