#include <bits/stdc++.h>
using namespace std;
int dist[20][20];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
string *s;
int h, w;
int func(int sx, int sy, int gx, int gy) {
  queue<pair<int, int> > q;
  dist[sx][sy] = 0;
  q.push(pair<int, int>(sx, sy));
  while (!q.empty()) {
    pair<int, int> u = q.front();
    int x = u.first, y = u.second;
    for (int i = 0; i < 4; i++) {
      int a = x + dx[i], b = y + dy[i];
      if (a < 0 || h <= a || b < 0 || w <= b || s[a][b] == '#' ||
          dist[a][b] != -1)
        continue;
      dist[a][b] = dist[x][y] + 1;
      q.push(pair<int, int>(a, b));
    }
    q.pop();
  }
  return dist[gx][gy];
}
int main() {
  cin >> h >> w;
  s = new string[h];
  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++) {
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          for (int m = 0; m < h; m++) {
            for (int n = 0; n < w; n++) dist[m][n] = -1;
          }
          ans = max(ans, func(i, j, k, l));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
