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

#define REP(i,j) for(int i=1;i<=j;i++)

char maze[21][21];
int max_step,step[21][21];
bool visited[21][21];
int dx[5]= {0,1,-1,0,0};
int dy[5]= {0,0,0,1,-1};

struct node {
	int x,y;
} note;
queue<node> q;

int main() {
	int x,y;
	scanf("%d%d",&x,&y);
	REP(i,x) {
		REP(j,y) {
			cin>>maze[i][j];
		}
	}
	REP(i,x) {
		REP(j,y) {
			memset(step,0,sizeof(step));
			memset(visited,0,sizeof(visited));
			if(maze[i][j]=='#')
			continue;
			q.push(node {i,j});
			visited[i][j]=true;
			while(!q.empty()) {
				node u=q.front();
				q.pop();
				int X=u.x;
				int Y=u.y;
				REP(k,4) {
					int xx=X+dx[k];
					int yy=Y+dy[k];
					if(maze[xx][yy]=='.'&&!visited[xx][yy]) {
						q.push(node {xx,yy});
						step[xx][yy]=step[X][Y]+1;
						max_step=max(max_step,step[xx][yy]);
						visited[xx][yy]=true;
					}
				}
			}
		}
	}
	printf("%d",max_step);
	return 0;
}