#include <bits/stdc++.h>
using namespace std;
bool a[21][21];
queue<pair<int, int>> q;
int n, m, dl[4] = {0, 1, 0, -1}, dc[4] = {1, 0, -1, 0}, v[21][21], mx = 1;
void lol(int i, int j) {
  while (!q.empty()) q.pop();
  for (int o = 1; o <= n; ++o) {
    for (int k = 1; k <= m; ++k) {
      v[o][k] = 0;
    }
  }
  v[i][j] = 1;
  q.push({i, j});
  while (!q.empty()) {
    i = q.front().first;
    j = q.front().second;
    mx = max(mx, v[i][j]);
    for (int k = 0; k < 4; ++k) {
      i += dl[k], j += dc[k];
      if (i >= 1 && i <= n && j >= 1 && j <= m && !v[i][j] && !a[i][j]) {
        v[i][j] = v[i - dl[k]][j - dc[k]] + 1;
        q.push({i, j});
      }
      i -= dl[k], j -= dc[k];
    }
    q.pop();
  }
}
int main() {
  int i, j;
  char c;
  cin >> n >> m;
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      cin >> c;
      a[i][j] = (c != '.');
    }
  }
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      lol(i, j);
    }
  }
  cout << mx - 1;
  return 0;
}
