#include <bits/stdc++.h>
using namespace std;
const int N = 22;
int n, m;
char mat[N][N];
int dist[N][N];
bool used[N][N];
int xx[4] = {+0, +0, -1, +1};
int yy[4] = {+1, -1, +0, +0};
bool in(int x, int y) { return (x >= 0 && y >= 0 && x < n && y < m); }
int go(int sx, int sy) {
  queue<pair<int, int> > q;
  q.push({sx, sy});
  memset(used, 0, sizeof used);
  used[sx][sy] = 1;
  dist[sx][sy] = 0;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    used[x][y] = 1;
    for (int i = 0; i < 4; i++) {
      int nx = x + xx[i];
      int ny = y + yy[i];
      if (in(nx, ny) && !used[nx][ny] && mat[nx][ny] != '#') {
        q.push({nx, ny});
        dist[nx][ny] = dist[x][y] + 1;
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      res = max(res, dist[i][j]);
    }
  }
  return res;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf(" %s", mat[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '#') continue;
      ans = max(ans, go(i, j));
    }
  }
  printf("%d\n", ans);
  return 0;
}
