#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
char str[maxn][maxn];
int num[maxn][maxn];
int vis[maxn][maxn];
int dir[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m, ans, res;
queue<pair<int, int> > Q;
int main(void) {
  int BFS(int start_x, int start_y);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      scanf("%c", &str[i][j]);
    }
  }
  ans = 0, res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (str[i][j] == '#') continue;
      res = BFS(i, j);
      ans = max(ans, res);
    }
  }
  cout << ans << endl;
  return 0;
}
bool Check(int first, int second) {
  if (first < 1 || second < 1 || first > n || second > m) return false;
  if (str[first][second] == '#') return false;
  return true;
}
int BFS(int start_x, int start_y) {
  pair<int, int> a, b;
  int count = 0;
  memset(num, 0, sizeof(num));
  a.first = start_x, a.second = start_y;
  Q.push(a);
  while (!Q.empty()) {
    a = Q.front();
    Q.pop();
    count = max(count, num[a.first][a.second]);
    int v = num[a.first][a.second];
    for (int i = 0; i < 4; i++) {
      b.first = a.first + dir[i][0];
      b.second = a.second + dir[i][1];
      if (!Check(b.first, b.second) || num[b.first][b.second]) continue;
      num[b.first][b.second] = v + 1;
      Q.push(b);
    }
  }
  return count;
}
