#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int search_maze(const vector<string> &field, int sx, int sy) {
  int height = field.size();
  int width = field[0].size();
  vector<vector<int>> dist(height, vector<int>(width, -1));
  queue<pair<int, int>> que;
  dist[sx][sy] = 0;
  que.push(make_pair(sx, sy));
  int ret;
  while (!que.empty()) {
    pair<int, int> currentPos = que.front();
    int x = currentPos.first;
    int y = currentPos.second;
    que.pop();
    for (int d = 0; d < (int)(4); d++) {
      int nx = x + dx[d];
      int ny = y + dy[d];
      if (nx < 0 || nx >= height || ny < 0 || ny >= width) continue;
      if (field[nx][ny] == '#') continue;
      if (dist[nx][ny] == -1) {
        que.push(make_pair(nx, ny));
        dist[nx][ny] = dist[x][y] + 1;
        ret = max(dist[nx][ny], ret);
      }
    }
  }
  return ret;
}
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> f(h);
  for (int i = 0; i < (int)(h); i++) cin >> f[i];
  int ans = 0;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (f[i][j] == '#') continue;
      ans = max(search_maze(f, i, j), ans);
    }
  cout << ans << endl;
  return 0;
}
