#include <iostream>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
using namespace std;

int bfs(char S[20][20], int H, int W, int x, int y, int N) {
	int count = 0;
	if (N == 0) {
		if (S[x][y] == '.') {
			if (x > 0 && S[x - 1][y] == '.') {
				S[x - 1][y] += 1;
				count++;
			}
			if (y > 0 && S[x][y - 1] == '.') {
				S[x][y - 1] += 1;
				count++;
			}
			if (x < H - 1 && S[x + 1][y] == '.') {
				S[x + 1][y] += 1;
				count++;
			}
			if (y < W - 1 && S[x][y + 1] == '.') {
				S[x][y + 1] += 1;
				count++;
			}
			S[x][y] -= 1;
		}
	}else
	FOR(H)FOR2(W) {
		if (S[i][j] == '.' + N) {
			if (i > 0 && S[i - 1][j] == '.') {
				S[i - 1][j] = '.' + N + 1;
				count++;
			}
			if (j > 0 && S[i][j - 1] == '.') {
				S[i][j - 1] = '.' + N + 1;
				count++;
			}
			if (i < H - 1 && S[i + 1][j] == '.') {
				S[i + 1][j] = '.' + N + 1;
				count++;
			}
			if (j < W - 1 && S[i][j + 1] == '.') {
				S[i][j + 1] = '.' + N + 1;
				count++;
			}
		}
	}
	//cout << count << endl;
	if (count) {
		N = bfs(S, H, W, x, y, N + 1);
	}
	return N;
}

int tansa(char S[20][20], int H, int W,int x,int y) {
	char temp[20][20];
	FOR(H)FOR2(W) {
		temp[i][j] = S[i][j];
	}
	int N=0;
	N = bfs(temp, H, W, x, y, N);
	return N;
}
int main() {
	int H, W,max=0;
	cin >> H >> W;
	char S[20][20] = { 0 };
	int count[H * W] = { 0 };
	FOR(H) {
		cin >> S[i];
	}
	FOR(H)FOR2(W){
			count[i*W+j]=tansa(S,H,W,i,j);
		}
	FOR(H*W){
		if (count[i] > max)
			max = count[i];
	}
	//FOR(H* W)
	//	cout << count[i] << endl;
	cout << max << endl;
}

