#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll cfmod = 998244353;
const int MAXN = 5 * 1e5+5;


string s1, s2;

int cont[MAXN], ac[MAXN], l, c;
char m[25][25];
int dist[25][25];

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

int ans = 0;

void bfs(pii a) {
	queue<pii> fila;
	fila.push(a);
	for(int i = 0; i < l; i++)
		for(int j = 0; j < c; j++)
			dist[i][j] = INF;
			
	dist[a.f][a.s] = 0;
	
	while(!fila.empty()) {
		pii atual = fila.front();
		ans = max(ans, dist[atual.f][atual.s]);
		fila.pop();
		
		for(int i = 0; i < 4; i++) {
			int ni = atual.f + x[i], nj = atual.s + y[i];
			if(ni < 0 or ni >= l or nj < 0 or nj >= c or m[ni][nj] == '#') continue;
			if(dist[atual.f][atual.s] + 1 < dist[ni][nj]) {
				dist[ni][nj] = dist[atual.f][atual.s]+1;
				fila.push({ni, nj});
			}
		}
	}
}

int32_t main() {
	cin >> l >> c;
	
	for(int i = 0; i < l; i++)
		for(int j = 0; j < c; j++)
			cin >> m[i][j];
	
	for(int i = 0; i < l; i++)
		for(int j = 0; j < c; j++)
			bfs({i, j});
			
	cout << ans << endl;
}
