#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 30;
const int M = 1e9 + 7;
int n, m, ans;
bool vis[maxn][maxn];
char a[30][30];
struct node {
  int x, y, step;
};
int to[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void bfs(int x, int y) {
  if (a[x][y] == '#') return;
  vis[x][y] = 1;
  queue<node> q;
  q.push(node{x, y, 0});
  while (!q.empty()) {
    node now = q.front();
    q.pop();
    ans = max(ans, now.step);
    for (int i = 0; i < 4; i++) {
      int xx = now.x + to[i][0];
      int yy = now.y + to[i][1];
      if (vis[xx][yy]) continue;
      if (a[xx][yy] == '#') continue;
      if (xx < 0 || xx >= n || yy < 0 || yy >= m) continue;
      vis[xx][yy] = 1;
      int s = now.step + 1;
      q.push(node{xx, yy, s});
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      memset(vis, 0, sizeof(vis));
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
