#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q;
queue<int> dist;
int n, m, maxx = 0;
char w[21][21];
char t[21][21];
int dx[] = {0, -1, +0, +1, +0};
int dy[] = {0, +0, +1, +0, -1};
int check(int x, int y) {
  if (x <= 0 || x > n || y <= 0 || y > m || (w[x][y] == '#') || t[x][y] == 1)
    return -1;
  return 1;
}
int lee(int x1, int y1) {
  int a, b, l, max2 = 0;
  while (!q.empty()) q.pop();
  while (!dist.empty()) dist.pop();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) t[i][j] = 0;
  }
  q.push({x1, y1});
  t[x1][y1] = 1;
  dist.push(0);
  while (!q.empty()) {
    if (dist.front() > max2) max2 = dist.front();
    for (int i = 1; i <= 4; i++) {
      a = q.front().first + dx[i];
      b = q.front().second + dy[i];
      l = dist.front();
      if (check(a, b) == 1) {
        q.push({a, b});
        dist.push(l + 1);
        t[a][b] = 1;
      }
    }
    q.pop();
    dist.pop();
  }
  return max2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> w[i][j];
  }
  int maxx = 0;
  for (int x1 = 1; x1 <= n; x1++) {
    for (int y1 = 1; y1 <= m; y1++) {
      int val = lee(x1, y1);
      if (val > maxx) maxx = val;
    }
  }
  cout << maxx;
  return 0;
}
