#include <bits/stdc++.h>
using namespace std;
char a[22][22];
int b[22][22];
int c[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int s, n, m;
struct node {
  int x, y, s;
} st, ed;
void bfs() {
  queue<node> q;
  q.push(st);
  node next;
  node cur;
  while (q.size()) {
    cur = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      next.x = cur.x + c[i][0];
      next.y = cur.y + c[i][1];
      next.s = cur.s + 1;
      if (next.x < n && next.x >= 0 && next.y < m && next.y >= 0 &&
          b[next.x][next.y] == 0 && a[next.x][next.y] == '.') {
        b[next.x][next.y] = 1;
        if (ed.x == next.x && ed.y == next.y) {
          s = next.s;
        }
        q.push(next);
      }
    }
  }
  return;
}
int main(void) {
  int T, t, x, y, k, mx = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') {
        st.x = i;
        st.y = j;
        for (int ii = 0; ii < n; ii++) {
          for (int jj = 0; jj < m; jj++) {
            if (a[ii][jj] == '.') {
              ed.x = ii;
              ed.y = jj;
              s = 0;
              memset(b, 0, sizeof(b));
              bfs();
              mx = max(mx, s);
            }
          }
        }
      }
    }
  }
  printf("%d\n", mx);
  return 0;
}
