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

int main() {
	constexpr int INF = 1<<30;
	constexpr int dx[4] = {1, 0, -1, 0};
	constexpr int dy[4] = {0, 1, 0, -1};

	int H, W;
	cin >> H >> W;
	vector<string> S(H, "");
	for(int i=0; i<H; i++) cin >> S[i];
	
	auto bfs = [&](int x, int y){
		int ans = 0;
		vector<vector<int>> dis(H, vector<int>(W, INF));
		queue<pair<int,int>> que;
		que.push({x, y});
		dis[x][y] = 0;
		while(!que.empty()) {
			pair<int,int> v = que.front();
			que.pop();
			for(int k=0; k<4; k++) {
				int nx = dx[k] + v.first;
				int ny = dy[k] + v.second;
				if(nx <= -1 || ny <= -1 || nx >= H || ny >= W || S[nx][ny] == '#') continue;
				if(dis[nx][ny] == INF){
					dis[nx][ny] = dis[v.first][v.second] + 1;
					ans = max(ans, dis[nx][ny]);
					que.push({nx, ny});
				}
			}
		}
		return ans;
	};

	int ans = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == '#')continue;
			ans = max(ans, bfs(i,j));
		}
	}

	cout << ans << endl;
	return 0;
}
