#include <bits/stdc++.h>

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int inf = 2147483647;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(cr x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(cr x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(cr x) {put(x), putchar(' ');}
I void pr2(cr x) {put(x), puts("");}

char ss[21][21];
int d[21][21];
queue<pii> q;

int main() {
	reg n = read(), m = read();
	fo(i, 1, n) scanf("%s", ss[i] + 1);
	reg ans = 0;
	fo(i, 1, n) fo(j, 1, m) {
		memset(d, 0, sizeof(d));
		d[i][j] = 1;
		q.push(pii{i, j});
		while(!q.empty()) {
			pii now = q.front(); q.pop();
			reg x = now.fi, y = now.se;
			ans = _max(ans, d[x][y]);
			fo(k, 0, 3) {
				reg nx = x + dx[k], ny = y + dy[k];
				if(nx < 1 || ny < 1 || nx > n || ny > m) continue;
				if(ss[nx][ny] == '#') continue;
				if(!d[nx][ny]) {
					d[nx][ny] = d[x][y] + 1;
					q.push(pii{nx, ny});
				}
			}
		}
	} pr2(ans - 1);
	return 0;
}

