#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int h, w;
char s[20 + 1][20 + 1];
int d[20 + 1][20 + 1];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  queue<pair<int, int> > que;
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) d[k][l] = INF;
      }
      que.push(pair<int, int>(i, j));
      d[i][j] = 0;
      while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int k = 0; k < 4; k++) {
          int nx = p.first + dx[k], ny = p.second + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != '#' &&
              d[nx][ny] == INF) {
            que.push(pair<int, int>(nx, ny));
            d[nx][ny] = d[p.first][p.second] + 1;
          }
        }
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (d[k][l] != INF) ans = max(ans, d[k][l]);
        }
      }
    }
  }
  cout << ans << endl;
}
