#include <bits/stdc++.h>
using namespace std;
char maze[20][20 + 1];
int sx, sy;
int gx, gy;
int h, w;
int d[20][20];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs() {
  queue<pair<int, int> > que;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = (int)2e9;
  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 i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' &&
          d[nx][ny] == (int)2e9) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      cin >> maze[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = i + 1; j < h * w; j++) {
      sx = i / w;
      sy = i % w;
      gx = j / w;
      gy = j % w;
      int tmp = bfs();
      if (tmp != (int)2e9) ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
