#include <bits/stdc++.h>
using namespace std;
long long h, w, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
string s[20];
long long run(long long sy, long long sx) {
  queue<pair<long long, long long> > que;
  int dist[20][20];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) dist[i][j] = -1;
  que.push(pair<long long, long long>(sy, sx));
  while (!que.empty()) {
    pair<long long, long long> now = que.front();
    long long y = now.first, x = now.second;
    for (int i = 0; i < 4; i++) {
      long long ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= h || nx < 0 || nx >= h) continue;
      if (s[ny][nx] == '#') continue;
      if (dist[ny][nx] == -1) {
        que.push(pair<long long, long long>(ny, nx));
        dist[ny][nx] = dist[y][x] + 1;
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) ret = max(ret, dist[i][j]);
  return ret;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      int res = run(i, j);
      ans = max(ans, res);
    }
  cout << ans;
  return 0;
}
