#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
int n, m;
char mapp[maxn][maxn];
int vis[maxn][maxn];
int go[8] = {1, 0, -1, 0, 0, 1, 0, -1};
struct point {
  int x, y, v;
};
int bfs(int i, int j) {
  queue<point> q;
  struct point ss;
  ss.x = i;
  ss.y = j;
  ss.v = 0;
  q.push(ss);
  int ci = 0;
  while (!q.empty()) {
    point now, temp;
    now = q.front();
    q.pop();
    if (now.v > ci) ci = now.v;
    for (int i = 0; i < 8; i += 2) {
      int xx = now.x + go[i];
      int yy = now.y + go[i + 1];
      if (xx >= 1 && yy >= 1 && xx <= n && yy <= m && vis[xx][yy] == 0 &&
          mapp[xx][yy] != '#') {
        temp.x = xx;
        temp.y = yy;
        temp.v = now.v + 1;
        q.push(temp);
        vis[xx][yy] = 1;
      }
    }
  }
  return ci;
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s", mapp[i] + 1);
  }
  int ci = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      memset(vis, 0, sizeof(vis));
      int cc = bfs(i, j);
      if (cc > ci) ci = cc;
    }
  printf("%d\n", ci);
  return 0;
}
