#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
long long h, w;
vector<string> board;
long long calc_max(pair<long long, long long> start) {
  long long maxn = 0;
  vector<vector<long long>> wl(h, vector<long long>(w));
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      if (board[i][j] == '#')
        wl[i][j] = -1;
      else
        wl[i][j] = LLONG_MAX;
    }
  wl[start.second][start.first] = 0;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  que.push(start);
  while (!que.empty()) {
    auto point = que.top();
    que.pop();
    long long x = point.first, y = point.second;
    for (long long i = 0; i < 4; i++) {
      int nx = point.first + dx[i];
      int ny = point.second + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && wl[ny][nx] != -1 &&
          wl[y][x] + 1 < wl[ny][nx]) {
        wl[ny][nx] = wl[y][x] + 1;
        que.push({nx, ny});
      }
    }
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (maxn < wl[i][j] && wl[i][j] != -1 && wl[i][j] != LLONG_MAX)
        maxn = wl[i][j];
    }
  }
  return maxn;
}
int main() {
  cin >> h >> w;
  board.resize(h);
  for (long long i = 0; i < h; i++) cin >> board[i];
  long long max_num = 0;
  for (long long y = 0; y < h; y++) {
    for (long long x = 0; x < w; x++) {
      max_num = max(max_num, calc_max({x, y}));
    }
  }
  cout << max_num << endl;
  return 0;
}
