#include<iostream>
#include<algorithm>
using namespace std;
int H,W,id[22][22],maxL,answer=0;
char s;
bool t[22][22]={0};

void move(int x,int y,int n){
	//cout<<x<<y<<endl;
	if(t[y][x]&&(id[y][x]>n||id[y][x]==-1)){
		id[y][x]=n;
		move(x+1,y,n+1);
		move(x-1,y,n+1);
		move(x,y+1,n+1);
		move(x,y-1,n+1);
	}
}

int main(){
	cin>>H>>W;
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++){
		cin>>s;
		t[i][j]=(s=='.');
	}
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++){
		for(int ii=1;ii<=H;ii++)for(int jj=1;jj<=W;jj++)id[ii][jj]=-1;
		maxL=0;
		move(i,j,0);
		for(int ii=1;ii<=H;ii++)for(int jj=1;jj<=W;jj++)maxL=max(maxL,id[ii][jj]);
		answer=max(maxL,answer);
	}
	cout<<answer;
	return 0;
}