#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int H,W;
	in(H,W);
	auto s = mv<string>(H);
	in(s);
	int ans = 0;
	auto bfs = [&](int sy,int sx)->int{
		auto dist = mv(H,W);
		fill(dist,INF);
		dist[sy][sx]=0;
		queue<pair<int,int>>st;
		st.push({sy,sx});
		int dx[] = {1,0,-1,0};
		int dy[] = {0,1,0,-1};
		while(st.size()){
			int i = st.front().first;
			int j = st.front().second;
			st.pop();
			REP(k,4){
				int ni = i + dy[k];
				int nj = j + dx[k];
				if(!IN(0,ni,H))continue;
				if(!IN(0,nj,W))continue;
				if(s[ni][nj] == '#')continue;
				if(dist[ni][nj]!=INF)continue;
				dist[ni][nj] = dist[i][j] + 1;
				st.push({ni,nj});
			}
		}
		int ret = -INF;
		REP(i,H)REP(j,W)if(dist[i][j]!=INF)CHMAX(ret,dist[i][j]);
		return ret;
	};
	REP(i,H)REP(j,W){
		if(s[i][j] == '#')continue;
		CHMAX(ans,bfs(i,j));
		out(i,j,ans);
	}
	out(ans);
}