#include <iostream>
#include <climits>
using namespace std;

#define X (INT_MAX/2-1)

int main () {
	int H, W;
	char maze[20][20];
	int d[400][400];

	cin >> H >> W;

	for (int s=0; s<H*W; s++)
		for (int g=0; g<H*W; g++)
			d[s][g] = X;

	for (int col=0; col<H; col++)
		for (int row=0; row<W; row++) {
			cin >> maze[col][row];
			if (maze[col][row] == '.') {
				if (col>0 && maze[col-1][row]=='.') {
					d[(col-1)*W+row][col*W+row] = 1;
					d[col*W+row][(col-1)*W+row] = 1;
				}
				if (row>0 && maze[col][row-1]=='.') {
					d[col*W+row-1][col*W+row] = 1;
					d[col*W+row][col*W+row-1] = 1;
				}
			}
		}

	for (int v=0; v<H*W; v++)
		for (int s=0; s<H*W; s++)
			for (int g=s+1; g<H*W; g++) {
				int tmp = d[s][v] + d[v][g];
				if (d[s][g] > tmp) {
					d[s][g] = tmp;
					d[g][s] = tmp;
				}
			}

	int max = -1;
	for (int s=0; s<H*W; s++)
		for (int g=s+1; g<H*W; g++) {
			if (max < d[s][g] && d[s][g] != X)
				max = d[s][g];
		}

	cout << max << endl;
	return 0;
}