#include <iostream>
#include <vector>
#include <cmath>
 
using namespace std;

char maze[20][20];

int H, W;
int grest;

int main()
{
  int i,j,k,l,m;
  string line;
  int col;
  int ret;
  int maxlen(int, int);

  cin >> H >> W;
  for (i=0; i<H; i++) {
    cin >> line;
    for (j=0; j<W; j++) {
      maze[i][j] = *(line.c_str()+j);
      if (maze[i][j] == '.') grest++;
    }
  }

  ret=0;
  for (i=0; i<H; i++) {
    for (j=0; j<W; j++) {
      if (maze[i][j] == '#') continue;
      ret = max(ret, maxlen(i,j));
    }
  }
  printf("%d\n", ret-1);

  return 0;
}

int mmap[20][20];
int maxlen(int i, int j) { // �_(i, j)����ł������_�܂ł̋���
  int p,q;
  int mlen=0;
  int mmove(int, int);

  for (p=0; p<H; p++)
    for (q=0; q<W; q++)
      mmap[p][q] = 0;
  p = i; q = j;
  mmap[p][q] = 1;
  mmove(p, q);
  for (p=0; p<H; p++)
    for (q=0; q<W; q++)
      mlen = max(mlen, mmap[p][q]);
//printf("maxlen(%d, %d) = %d\n", i, j, mlen);
  return mlen;
}
void mmove(int p, int q) {  // �_(p,q)����C�ӂ̓_�Ɉړ����A(p,q)����̋������L�^����
  int l;

  l = mmap[p][q]+1;
  if (p>0 && maze[p-1][q] == '.') { // ��ړ�
    if (mmap[p-1][q] == 0 || mmap[p-1][q]>l) {
      mmap[p-1][q] = l;
      mmove(p-1, q);
    }
  }
  if (q>0 && maze[p][q-1] == '.') { // ���ړ�
    if (mmap[p][q-1] == 0 || mmap[p][q-1]>l) {
      mmap[p][q-1] = l;
      mmove(p, q-1);
    }
  }
  if (p<W-1 && maze[p+1][q] == '.') { // ���ړ�
    if (mmap[p+1][q] == 0 || mmap[p+1][q]>l) {
      mmap[p+1][q] = l;
      mmove(p+1, q);
    }
  }
  if (q<H-1 && maze[p][q+1] == '.') { // �E�ړ�
    if (mmap[p][q+1] == 0 || mmap[p][q+1]>l) {
      mmap[p][q+1] = l;
      mmove(p, q+1);
    }
  }
}
