#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
int bfs(int N, int M, vector<vector<char>> field, int sx, int sy, int gx,
        int gy) {
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  int d[N][M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      d[i][j] = INF;
    }
  }
  queue<pair<long long, long long>> que;
  que.push(pair<long long, long long>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<long long, long long> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) {
      break;
    }
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < N && 0 <= ny && ny < M && field[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<long long, long long>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
int main() {
  int h, w, i, j;
  cin >> h;
  cin >> w;
  vector<vector<char>> field(h, vector<char>(w));
  int res = 0;
  int sx, sy, gx, gy;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> field[i][j];
    }
  }
  int ans = 0;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (field[i][j] == '.') {
        sx = i;
        sy = j;
      }
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (field[k][l] == '.') {
            gx = k;
            gy = l;
            ans = max(ans, bfs(h, w, field, sx, sy, gx, gy));
          }
        }
      }
    }
  }
  cout << ans << endl;
}
