#include <bits/stdc++.h>
using namespace std;
const int Maxn = 22;
const int Inf = 1000000000;
const int Maxd = 4;
const int dy[Maxd] = {-1, 0, 1, 0};
const int dx[Maxd] = {0, -1, 0, 1};
int n, m;
char B[Maxn][Maxn];
int dist[Maxn][Maxn];
int res;
void Solve(int r, int c) {
  fill((int*)dist, (int*)dist + Maxn * Maxn, Inf);
  dist[r][c] = 0;
  queue<pair<int, int> > Q;
  Q.push(pair<int, int>(r, c));
  while (!Q.empty()) {
    pair<int, int> v = Q.front();
    Q.pop();
    res = max(res, dist[v.first][v.second]);
    for (int i = 0; i < Maxd; i++) {
      pair<int, int> u = pair<int, int>(v.first + dy[i], v.second + dx[i]);
      if (0 <= u.first && u.first < n && 0 <= u.second && u.second < m &&
          B[u.first][u.second] == '.' &&
          dist[v.first][v.second] + 1 < dist[u.first][u.second]) {
        dist[u.first][u.second] = dist[v.first][v.second] + 1;
        Q.push(u);
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", &B[i]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (B[i][j]) Solve(i, j);
  printf("%d\n", res);
  return 0;
}
