#include <bits/stdc++.h>
using namespace std;
long long inf = 100000000;
long long v[205];
long long x[20000005];
long long a[10005], b[10005];
long long dp[10005][10005];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int h, w;
char s[25][25];
int bfs(int sx, int sy) {
  int dist[25][25];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      dist[i][j] = inf;
    }
  }
  queue<pair<long long, long long> > v;
  v.push(pair<long long, long long>{sx, sy});
  dist[sx][sy] = 0;
  while (v.size()) {
    pair<long long, long long> now = v.front();
    v.pop();
    for (int i = 0; i < 4; i++) {
      int xnext = now.first + dy[i];
      int ynext = now.second + dx[i];
      if ((0 <= xnext && xnext < h) && (0 <= ynext && ynext < w)) {
        char a = s[xnext][ynext];
        if ((dist[xnext][ynext] == inf) && (s[xnext][ynext] != '#')) {
          dist[xnext][ynext] = dist[now.first][now.second] + 1;
          v.push(pair<long long, long long>{xnext, ynext});
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (dist[i][j] != inf) {
        res = max(res, dist[i][j]);
      }
    }
  }
  return res;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int res = bfs(i, j);
      if (res != inf) {
        ans = max(ans, res);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
