//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int H, W;
vector<vector<bool>>mat(21, vector<bool>(21, false));
vector<vector<bool>>flag(21, vector<bool>(21, false));
vector<vector<bool>>flagb(21, vector<bool>(21, false));
vector<vector<int>>flag2(21, vector<int>(21, 99999999));
vector<vector<int>>flag2b(21, vector<int>(21, 99999999));
int gy, gx, maxn = 0, minn = 999999;
bool flag3[21][21][21][21];
bool dame = false;

void show() {
	cout << endl;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (flag2[i][j] > 999999) {
				cout << "#" << " ";
			}
			else {
				cout << flag2[i][j] << " ";
			}
		}
		cout << endl;
	}
	cout << endl;
}

int func(int y, int x, int cnt) {

	//if (dame == true) {
	//	return 0;
	//}


	if (y < 0 || x < 0 || y >= H || x >= W) {
		return 0;
	}


	if (flag[y][x] == true) {
		return 0;
	}

	if (flag2[y][x] <= cnt) {
		return 0;
	}

	if (mat[y][x] == true) {
		return 0;
	}

	if (cnt >= minn){
		return 0;
	}

	//if (y == gy && x == gx) {
	//	if (cnt < minn) {
	//		minn = cnt;
	//	}

	//	if (cnt <= maxn) {
	//		dame = true;
	//	}

	//	return 0;
	//}

	flag2[y][x] = cnt;

	func(y - 1, x, cnt + 1);
	func(y + 1, x, cnt + 1);
	func(y , x - 1, cnt + 1);
	func(y, x + 1, cnt + 1);


	return 0;
}



signed main() {
	memset(flag3, 0, sizeof(flag3));

	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < s.length(); j++) {
			if (s[j] == '#') {
				mat[i][j] = true;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {

			func(i, j, 0);
			//show();

			vector<int>list5;
			for (int y = 0; y < H; y++) {
				for (int x = 0; x < W; x++) {
					if (flag2[y][x] != 99999999) {
						//flag[y][x] = true;
						list5.push_back(flag2[y][x]);
					}
				}
			}

			if (list5.size() > 0) {
				sort(list5.begin(), list5.end());
				int sa = abs(list5[0] - list5[list5.size() - 1]);
				maxn = max(maxn, sa);
			}

			flag2 = flag2b;

			//cout << "i->" << i << " maxn->" << maxn << endl;
		}
	}

	cout << maxn << endl;

	return 0;
}

Measured memory_bytes: 512