#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
void faltu() { cerr << '\n'; }
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
  cerr << arg << ' ';
  faltu(rest...);
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int mx = 25;
int dist[mx][mx], n, m;
char c[mx][mx];
void dfs(int i, int j, int d) {
  if (dist[i][j] > d)
    dist[i][j] = d;
  else
    return;
  for (int k = 0; k < 4; k++) {
    int x = dx[k] + i;
    int y = dy[k] + j;
    if (x <= n && x >= 1 && y <= m && y >= 1 && c[x][y] != '#') {
      dfs(x, y, d + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 1; k <= n; k++) {
        for (int l = 1; l <= m; l++) {
          dist[k][l] = inf;
        }
      }
      dist[i][j] = 0;
      if (c[i][j] != '#') dfs(i, j, 0);
      for (int k = 1; k <= n; k++) {
        for (int l = 1; l <= m; l++) {
          if (dist[k][l] != inf) ans = max(ans, dist[k][l]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
