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