#include <bits/stdc++.h>
using namespace std;
char a[21][21];
int n, m;
unordered_map<int, int> dis;
int bfs(int x1, int y1, int x2, int y2) {
  queue<pair<int, int>> Q;
  dis.clear();
  dis[n * x1 + y1] = 0;
  Q.push({x1, y1});
  int dx[] = {1, -1, 0, 0};
  int dy[] = {0, 0, -1, 1};
  while (!Q.empty()) {
    auto p = Q.front();
    Q.pop();
    int x = p.first, y = p.second;
    if (x == x2 && y == y2) break;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx >= n || nx < 0 || ny >= m || ny < 0 || a[nx][ny] == '#') continue;
      if (dis.find(n * nx + ny) != dis.end()) continue;
      dis[n * nx + ny] = dis[n * x + y] + 1;
      Q.push({nx, ny});
    }
  }
  return dis[n * x2 + y2];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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] == '#') continue;
      for (int x = 0; x < n; x++) {
        for (int y = 0; y < m; y++) {
          if (a[x][y] == '#') continue;
          ans = max(ans, bfs(i, j, x, y));
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
