#include <bits/stdc++.h>
using namespace std;
const int N = 25;
queue<pair<int, int> > q;
char c[N][N];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dist[N][N], ans, n, m;
void bfs(int x, int y) {
  q.push(make_pair(x, y));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dist[i][j] = -1;
  dist[x][y] = 0;
  while (!q.empty()) {
    x = q.front().first;
    y = q.front().second;
    q.pop();
    ans = max(ans, dist[x][y]);
    for (int i = 0; i < 4; i++) {
      int x2 = x + dx[i];
      int y2 = y + dy[i];
      if (x2 < 0 || y2 < 0 || x2 >= n || y2 >= m || c[x2][y2] == '#') continue;
      if (dist[x2][y2] == -1) {
        dist[x2][y2] = dist[x][y] + 1;
        q.push(make_pair(x2, y2));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
