#include<bits/stdc++.h>
using namespace std;

#define INF (1<<30)

char maze[20][20];
int h,w;

int search(int sy,int sx, int gy, int gx){
	int memo[20][20],dy[4]={-1,1,0,0},dx[4]={0,0,-1,1};
	for(int i=0;i<20;i++){
		for(int j=0;j<20;j++){
			memo[i][j]=0;
		}
	}

	queue< pair<int,int> >Q;

	Q.push({sy,sx});
	memo[sy][sx]=1;

	while(Q.empty()==false){
		pair<int,int>now=Q.front();	Q.pop();
		int y=now.first, x=now.second;

		for(int i=0;i<4;i++){
			int nY=y+dy[i], nX=x+dx[i];
			if(nY<0||nX<0||nY>=h||nX>=w||maze[nY][nX]=='#'||memo[nY][nX])continue;

			memo[nY][nX]=memo[y][x]+1;
			Q.push({nY,nX});
		}
	}

	return memo[gy][gx]-1;

}

int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){

			cin>>maze[i][j];
		}
	}

	int ans=0;

	for(int sy=0;sy<h;sy++){
		for(int sx=0;sx<w;sx++){
			if(maze[sy][sx]=='#')continue;

			for(int gy=0;gy<h;gy++){
				for(int gx=0;gx<w;gx++){
					if(maze[gy][gx]=='#')continue;

					ans=max(ans,search(sy,sx,gy,gx));

				}
			}
		}
	}

	cout<<ans<<endl;
	return 0;
}
