#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;


template<typename T>
void dump(T *arr, int h, int w){
	rep(i,h){
		rep(j,w) cout << arr[i][j] << "\t";
		cout << "\n";
	}
}

template<typename T>
void dump(T *arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

template<typename T>
void dump(vector<T> arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

const int INF = 1e9;
const int MOD = 1e9+7;

bool compare(P a, P b){
	if(a.second != b.second) return a.second > b.second;
	else	return a.first > b.first;
}


int digits(ll num){
	ll d=0;
	while(num >= 1){
		num/= 10;
		d++;
	}
	return d;
}

ll pow_kai(ll a, int n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}


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

	int h, w;
	cin >> h >> w;

	char s[h][w];
	rep(i, h) rep(j, w) cin >> s[i][j];

	int ans=0;
	queue<tuple<int, int, int>> q;
	int hh, ww, d;
	rep(i, h) rep(j, w){
		if(s[i][j] == '#') continue;
		q.push(make_tuple(i, j, 0));
		bool visited[h][w] = {};
		int most_distant = 0;
		while(!q.empty()){
			tie(hh, ww, d) = q.front();
			q.pop();
			//auto t = q.front();
			//int hh = get<0>(t), ww=get<1>(t), d=get<2>(t);
			most_distant = max(most_distant, d);
			visited[hh][ww] = true;
			if(hh != 0 && (!visited[hh-1][ww]) && s[hh-1][ww] == '.') q.push(make_tuple(hh-1, ww, d+1));
			if(hh != h-1 && (!visited[hh+1][ww]) && s[hh+1][ww] == '.') q.push(make_tuple(hh+1, ww, d+1));
			if(ww != 0 && (!visited[hh][ww-1]) && s[hh][ww-1] == '.')q.push(make_tuple(hh, ww-1, d+1));
			if(ww != w-1 && (!visited[hh][ww+1]) && s[hh][ww+1] == '.') q.push(make_tuple(hh, ww+1, d+1));
		}
		ans = max(ans, most_distant);
	}

	cout << ans << "\n";
		
	return 0;
}
