#include <bits/stdc++.h>
using namespace std;
char map[30][30];
int vis[30][30], n, m, cnt = 0;
int dir[4][2] = {0, 1, 0, -1, -1, 0, 1, 0};
struct node {
  int x, y, step;
} k[30];
void bfs(int x, int y) {
  memset(vis, 0, sizeof(vis));
  int i;
  queue<node> q;
  node pre, next;
  pre.x = x, pre.y = y, pre.step = 0;
  q.push(pre);
  vis[pre.x][pre.y] = 1;
  while (!q.empty()) {
    pre = q.front();
    q.pop();
    cnt = cnt > pre.step ? cnt : pre.step;
    for (i = 0; i < 4; i++) {
      next.x = pre.x + dir[i][0], next.y = pre.y + dir[i][1];
      if (next.x < 1 || next.x > n || next.y < 1 || next.y > m) continue;
      if (!vis[next.x][next.y] && map[next.x][next.y] == '.') {
        next.step = pre.step + 1;
        q.push(next);
        vis[next.x][next.y] = 1;
      }
    }
  }
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%s", map[i] + 1);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) bfs(i, j);
  printf("%d\n", cnt);
}
