#include <bits/stdc++.h>
using namespace std;
const int INF = 1e5;
char s[20][20];
int h, w;
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
const long long mod = 1e9 + 7;
int func(int sx, int sy) {
  int d[h][w];
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      d[i][j] = INF;
    }
  int ma = 0;
  queue<pair<int, int> > que;
  d[sx][sy] = 0;
  que.push(pair<int, int>(sx, sy));
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    int x = p.first, y = p.second;
    for (long long i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx > h || ny > w || d[nx][ny] != INF ||
          s[nx][ny] == '#')
        continue;
      d[nx][ny] = d[x][y] + 1;
      ma = max(ma, d[nx][ny]);
      que.push(pair<int, int>(nx, ny));
    }
  }
  return ma;
}
int main() {
  cin >> h >> w;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  int ans = 0;
  for (long long i = 0; i < h; i++)
    for (long long j = 0; j < w; j++) {
      ans = max(ans, func(i, j));
    }
  cout << ans << endl;
  return 0;
}
