#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  char s[30][30];
  long long dist[30][30];
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> s[i][j];
      dist[i][j] = -1;
    }
  }
  long long sy, sx;
  long long ans = 0;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      sy = i;
      sx = j;
      dist[sy][sx] = 0;
      queue<pair<long long, long long> > que;
      que.push(pair<long long, long long>(sy, sx));
      while (!que.empty()) {
        pair<long long, long long> p = que.front();
        que.pop();
        for (long long m = 0; m < 4; m++) {
          long long ny = p.first + dy[m];
          long long nx = p.second + dx[m];
          if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] != '#' &&
              dist[ny][nx] == -1) {
            que.push(pair<long long, long long>(ny, nx));
            dist[ny][nx] = dist[p.first][p.second] + 1;
          }
        }
      }
      for (long long k = 0; k < h; k++) {
        for (long long l = 0; l < w; l++) {
          ans = max(ans, dist[k][l]);
          dist[k][l] = -1;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
