#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[30][30];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int bfs(int s) {
  queue<int> q;
  q.push(s);
  vector<int> visited(n * m, -1);
  visited[s] = 0;
  int ret = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    ret = max(ret, visited[u]);
    int x = u / m, y = u % m;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (visited[nx * m + ny] > 0 || a[nx][ny] == '#') continue;
      visited[nx * m + ny] = visited[u] + 1;
      q.push(nx * m + ny);
    }
  }
  return ret;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (a[i][j] != '#') ans = max(ans, bfs(i * m + j));
  }
  cout << ans << endl;
  return 0;
}
