#include <bits/stdc++.h>
using namespace std;
const int maxn = 21;
bool mat[maxn][maxn];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, 1};
int n, m, d[maxn][maxn];
bool can(int r, int c) {
  return (r >= 0 && r < n && c >= 0 && c < m && mat[r][c] && d[r][c] == -1);
}
int mbfs(pair<int, int> start) {
  memset(d, -1, sizeof(d));
  queue<pair<int, int>> q;
  q.push(start);
  d[start.first][start.second] = 0;
  int mx = 0;
  while (q.size()) {
    int r = q.front().first, c = q.front().second;
    mx = max(d[r][c], mx);
    q.pop();
    for (int i = 0; i < 4; i++)
      if (can(r + dx[i], c + dy[i])) {
        int nr = r + dx[i], nc = c + dy[i];
        d[nr][nc] = d[r][c] + 1;
        q.push({nr, nc});
      }
  }
  return mx;
}
int main() {
  scanf("%d %d\n", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) mat[i][j] = (getchar() == '.');
    getchar();
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) ans = max(ans, mbfs({i, j}));
  }
  cout << ans << endl;
  return 0;
}
