#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, bool> pib;

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

typedef vector<double> vf;

typedef long double ld;

#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

#define printItr(A) for(auto itr = A.begin(); itr != A.end(); ++itr){cout << * itr << ", ";}cout << endl;

const double PI = 3.141592653589793;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

bool eq(vi P, vi Q) {
	rep(i, P.size()) {
		if (P[i] != Q[i]) {
			return false;
		}
	}
	return true;
}

ll gcd(ll a, ll b)
{
	if (a%b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a%b));
	}
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll H, W;
bool inrange(ll h, ll w) {
	if (h < 0 || h >= H || w < 0 || w >= W) {
		return false;
	}
	return true;
}

ll toS(ll h, ll w) {
	return h * W + w;
}

int main() {
	cin >> H >> W;

	ll S = H * W;
	vi F(S, false);
	drep(h, H, w, W) {
		char c;
		cin >> c;
		bool f = c == '.';

		F[toS(h, w)] = f;
	}

	vvi graph(S, vi(0));

	drep(h, H, w, W) {
		ll dh = 0, dw = 0;
		ll s = toS(h, w);
		if (!F[s])
			continue;
		for(dh = 0, dw = -1; dw <= 1; dw += 2) {
			if (!F[toS(h + dh, w + dw)])
				continue;
			if (!inrange(h + dh, w + dw))
				continue;

			graph[s].pb(toS(h + dh, w + dw));
			graph[toS(h + dh, w + dw)].pb(s);
		}
		for(dh = -1, dw = 0; dh <= 1; dh += 2) {
			if (!F[toS(h + dh, w + dw)])
				continue;
			if (!inrange(h + dh, w + dw))
				continue;

			graph[s].pb(toS(h + dh, w + dw));
			graph[toS(h + dh, w + dw)].pb(s);
		}
	}

	ll ans = 0;
	rep(s, S) {
		if (!F[s])
			continue;

		queue<ll> que;
		que.push(s);
		vi D(S, -1);
		D[s] = 0;

		while (!que.empty()) {
			ll v = que.front();
			que.pop();

			for (auto nv: graph[v]) {
				if (D[nv] == -1) {
					D[nv] = D[v] + 1;
					que.push(nv);
				}
			}
		}

		rep(i, S) {
			if (ans < D[i]) {
				ans = D[i];
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256