#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
int n, m, a[maxn][maxn], ans, d[maxn][maxn], vis[maxn][maxn];
int dx[5] = {0, 0, 0, -1, 1};
int dy[5] = {0, -1, 1, 0, 0};
inline bool can(int x, int y) {
  if (x < 1 || y < 1 || x > n || y > m || a[x][y])
    return 0;
  else
    return 1;
}
inline void bfs(int sx, int sy) {
  queue<int> qx, qy;
  memset(d, 0, sizeof(d));
  memset(vis, 0, sizeof(vis));
  qx.push(sx);
  qy.push(sy);
  vis[sx][sy] = 1;
  while (!qx.empty()) {
    int x = qx.front(), y = qy.front();
    qx.pop();
    qy.pop();
    for (int k = 1; k <= 4; k++) {
      int nx = x + dx[k], ny = y + dy[k];
      if (!can(nx, ny) || vis[nx][ny]) continue;
      d[nx][ny] = d[x][y] + 1;
      vis[nx][ny] = 1;
      ans = max(ans, d[nx][ny]);
      qx.push(nx);
      qy.push(ny);
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char opt;
      cin >> opt;
      if (opt == '#') a[i][j] = 1;
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
