#include <bits/stdc++.h>
using namespace std;
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const int MAX_H = 30;
const int MAX_W = 30;
int h, w;
char maze[MAX_H][MAX_W];
const int INI = -1;
int dist[MAX_H][MAX_W];
int bfs2(int sy, int sx) {
  if (maze[sy][sx] == '#') return 0;
  for (int i = 0; i < (int)(MAX_H); i++)
    for (int j = 0; j < (int)(MAX_W); j++) dist[i][j] = INI;
  dist[sy][sx] = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(sy, sx));
  while (que.size()) {
    auto p = que.front();
    que.pop();
    for (int i = 0; i < (int)(4); i++) {
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if (ny >= 0 && nx >= 0 && ny < h && nx < w && dist[ny][nx] &&
          maze[ny][nx] != '#') {
        que.push(pair<int, int>(ny, nx));
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) ret = max(ret, dist[i][j]);
  return ret;
}
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 res = 0;
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      res = max(bfs2(i, j), res);
    }
  }
  cout << res << endl;
  return 0;
}
