#include <bits/stdc++.h>
using namespace std;
int h, w;
char s[25][25];
int si[405], sj[405], snum;
int maxstep = 0;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
typedef struct node {
  int x, y;
  int step;
} Node;
queue<Node> q;
int visit[25][25];
void init() {
  int i, j;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      visit[i][j] = 0;
    }
  }
}
int bfs(int sx, int sy) {
  int i;
  int newx, newy, newstep;
  Node snode, qnode, tnode;
  snode.x = sx, snode.y = sy;
  snode.step = 0;
  q.push(snode);
  int localmax = -1;
  while (!q.empty()) {
    qnode = q.front();
    q.pop();
    visit[qnode.x][qnode.y] = 1;
    if (localmax < qnode.step) localmax = qnode.step;
    for (i = 0; i < 4; i++) {
      newx = qnode.x + x[i];
      newy = qnode.y + y[i];
      newstep = qnode.step + 1;
      if (newx >= 0 && newx < h && newy >= 0 && newy < w &&
          s[newx][newy] == '.' && visit[newx][newy] == 0) {
        tnode.x = newx, tnode.y = newy, tnode.step = newstep;
        q.push(tnode);
      }
    }
  }
  return localmax;
}
int main() {
  scanf("%d%d", &h, &w);
  int i, j;
  for (i = 0; i < h; i++) {
    scanf("%s", s[i]);
    for (j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        si[snum] = i, sj[snum] = j;
        snum++;
      }
    }
  }
  int localmax = 0;
  for (i = 0; i < snum; i++) {
    init();
    localmax = bfs(si[i], sj[i]);
    if (localmax > maxstep) maxstep = localmax;
  }
  printf("%d\n", maxstep);
  return 0;
}
