#include <bits/stdc++.h>
using namespace std;
const int MAX = 25;
const int INF = 1000000000;
int h, w;
int d[MAX][MAX];
int ans = 0;
char field[MAX][MAX];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(int s1, int s2, int g1, int g2) {
  int sx = s1;
  int sy = s2;
  int gx = g1;
  int gy = g2;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) d[i][j] = INF;
  }
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sx, sy));
  d[sx][sy] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    if (p.first == gx && p.second == gy) break;
    for (int t = 0; t < 4; t++) {
      int nx = p.first + dx[t];
      int ny = p.second + dy[t];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  if (d[gx][gy] < INF)
    return d[gx][gy];
  else
    return -1;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> field[i][j];
    }
  }
  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++) {
          ans = max(ans, bfs(i, j, k, l));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
