#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N = 30;
const int INF = 1e5;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dist[N][N];
char loc[N][N];
bool vis[N][N];
int ans = 0;
void bfs(int i, int j) {
  memset(vis, 0, sizeof vis);
  memset(dist, -1, sizeof dist);
  queue<pair<int, int>> q;
  vis[i][j] = 1;
  q.push({i, j});
  dist[i][j] = 0;
  while (!q.empty()) {
    i = q.front().first;
    j = q.front().second;
    q.pop();
    for (int d = 0; d < 4; d++) {
      int x = i + dx[d];
      int y = j + dy[d];
      if (vis[x][y] || loc[x][y] != '.') continue;
      dist[x][y] = dist[i][j] + 1;
      vis[x][y] = 1;
      q.push({x, y});
      ans = max(ans, dist[x][y]);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> loc[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (loc[i][j] == '#') continue;
      bfs(i, j);
    }
  }
  cout << ans << "\n";
  return 0;
}
