#include <bits/stdc++.h>
using namespace std;
const int INF = 100000000;
int main() {
  int N, M;
  cin >> N >> M;
  char ma[N][M + 1];
  for (int(i) = 0; (i) < (N); (i)++)
    for (int(j) = 0; (j) < (M); (j)++) cin >> ma[i][j];
  int d[N][M + 1];
  int dx[4] = {1, 0, -1, 0}, dy[4] = {1, 0, -1, 0};
  int ans = 0;
  for (int(sx) = 0; (sx) < (N); (sx)++)
    for (int(sy) = 0; (sy) < (M); (sy)++)
      for (int(gx) = 0; (gx) < (N); (gx)++)
        for (int(gy) = 0; (gy) < (M); (gy)++) {
          if (ma[sx][sy] == '#') continue;
          if (ma[gx][gy] == '#') continue;
          queue<pair<int, int> > que;
          for (int(i) = 0; (i) < (N); (i)++)
            for (int(j) = 0; (j) < (M); (j)++) d[i][j] = -1;
          que.push(pair<int, int>(sx, sy));
          d[sx][sy] = 0;
          while (!que.empty()) {
            pair<int, int> p = que.front();
            que.pop();
            if (p.first == gx && p.second == gy) break;
            for (int(a) = 0; (a) < (4); (a)++) {
              int nx = p.first + dx[a], ny = p.second + dy[a];
              if (0 <= nx && 0 <= ny && nx < N && ny < M && ma[nx][ny] != '#' &&
                  d[nx][ny] == -1) {
                que.push(pair<int, int>(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
              }
            }
          }
          ans = max(ans, d[gx][gy]);
        }
  cout << ans << endl;
}
