#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector<Pii> v[100001];
ll dp2[300000][60]={};
int main() {
	int h,w;
	cin>>h>>w;
	int d[h][w]={};
	queue<Piii>  que;
	int r=0;
	rep(i,h){
		string s;
		cin>>s;
		rep(j,w){
			if(s[j]=='#')d[i][j]=1;
		}
	}
	rep(i,h){
		rep(j,w){
			que.push(Piii(Pii(i,j),1));
			int dp[h][w]={};
			int r2=0;
			while(!que.empty()){
				Piii p=que.front();que.pop();
				int x=p.first.first;
				int y=p.first.second;
				int cost=p.second;
				if(cost>=dp[x][y]&&dp[x][y]>0)continue;
				if(d[x][y]>0)continue;
				dp[x][y]=cost;
				if(x>0)que.push(Piii(Pii(x-1,y),cost+1));
				if(x<h-1)que.push(Piii(Pii(x-+1,y),cost+1));
				if(y>0)que.push(Piii(Pii(x,y-1),cost+1));
				if(y<w-1)que.push(Piii(Pii(x,y+1),cost+1));
				r2=max(r2,cost);
			}
//			cout<<r2<<endl;
			r=max(r,r2);
		}
	}
	cout<<(r-1)<<endl;
	return 0;
}
