#include <bits/stdc++.h>
using namespace std;
int vis[30][30] = {};
char a[30][30] = {};
int st[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};
struct s {
  int x, y, cnt;
} no, ne, an;
queue<s> q;
int n, m, i;
int main() {
  int anso, anst, ans, j, ANS = 0;
  int bfs(struct s aa);
  while (~scanf("%d%d", &n, &m)) {
    for (i = 0; i < n; i++) scanf("%s", a[i]);
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (a[i][j] == '#') continue;
        no.x = i;
        no.y = j;
        no.cnt = 0;
        ans = bfs(no);
        ANS = ans > ANS ? ans : ANS;
        memset(vis, 0, sizeof(vis));
      }
    }
    printf("%d\n", ANS);
    ANS = 0;
    memset(a, 0, sizeof(a));
    memset(vis, 0, sizeof(vis));
    while (!q.empty()) q.pop();
  }
}
int bfs(struct s aa) {
  int ans = 0;
  q.push(no);
  vis[no.x][no.y] = 1;
  while (!q.empty()) {
    no = q.front();
    for (i = 0; i < 4; i++) {
      ne.x = no.x + st[i][0];
      ne.y = no.y + st[i][1];
      ne.cnt = no.cnt + 1;
      if (ne.x < 0 || ne.y < 0 || ne.x >= n || ne.y >= m || vis[ne.x][ne.y] ||
          a[ne.x][ne.y] == '#')
        continue;
      vis[ne.x][ne.y] = 1;
      ans = ne.cnt > ans ? ne.cnt : ans;
      q.push(ne);
    }
    q.pop();
  }
  return ans;
}
