#include <bits/stdc++.h>
using namespace std;
long long poz(long long a) {
  if (a < 0) return (-a);
  return a;
}
int n, m;
int a[20 + 1][20 + 1];
string s;
int rez = 0;
pair<int, int> q[20 * 20 + 1];
int dist[20 + 1][20 + 1];
const int dl[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, -1, 1};
bool inMat(int l, int c) { return l >= 1 && l <= n && c >= 1 && c <= m; }
void doDfs(int l, int c) {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) dist[i][j] = n * m * 2;
  }
  int st = 1, dr = 0;
  q[++dr] = {l, c};
  dist[l][c] = 0;
  while (st <= dr) {
    auto cr = q[st++];
    int cl = cr.first;
    int cc = cr.second;
    for (int dir = 0; dir < 4; dir++) {
      int nl = cl + dl[dir];
      int nc = cc + dc[dir];
      if (inMat(nl, nc) && a[nl][nc] == 0 && dist[cl][cc] + 1 < dist[nl][nc]) {
        dist[nl][nc] = dist[cl][cc] + 1;
        q[++dr] = {nl, nc};
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (dist[i][j] != n * m * 2) rez = max(rez, dist[i][j]);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    for (int j = 1; j <= m; j++) a[i][j] = (s[j - 1] == '#' ? 1 : 0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      doDfs(i, j);
    }
  }
  cout << rez << "\n";
  return 0;
}
