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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n,m;
char a[21][21];
int d[21][21];
int res=-2e18;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};

signed main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	
	cin>>n>>m;
	forn(i,0,n) forn(j,0,m) cin>>a[i][j];
	forn(i,0,n){
		forn(j,0,m){
			memset(d,-1,sizeof(d));
			if (a[i][j]=='#') continue;
			queue<int> q;
			q.push(i); q.push(j);
			d[i][j]=0;
			while (!q.empty()){
				int x=q.front(); q.pop();
				int y=q.front(); q.pop();
				forn(k,0,4){
					int nx=x+dx[k];
					int ny=y+dy[k];
					if (nx<0 || nx>=n || ny<0 || ny>=m) continue;
					if (d[nx][ny]==-1 && a[nx][ny]=='.'){
						d[nx][ny]=d[x][y]+1;
						q.push(nx); q.push(ny);
					}
				}
			}
			forn(r,0,n)
				forn(c,0,m)
					res=max(res,d[r][c]);
		}
	}
	cout<<res<<endl;
	return 0;
}