#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i = 0; i < n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
 
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
 
		if (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};

vector<int> dist;
int dfs(int pos, vector<vector<int> > &g){
	int maxDist = 0;
	for (int i = 0; i < g[pos].size(); i++){
		int to = g[pos][i];
		if (dist[to] != -1){
			maxDist = max(maxDist, dist[to]+1);
			continue;
		}
		int toDist = dfs(to, g);
		maxDist = max(maxDist, toDist + 1);
	}
	dist[pos] = maxDist;
	return maxDist;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}



int main(){
	int H,W; cin >> H >> W;
	char s[22][22];
	int distance[22][22];
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> s[i][j];
		}
	}
	pair<int, int> p;

	int maxDist = 0;
	for (int Yst = 0; Yst < H; Yst++){
		for (int Xst = 0; Xst < W; Xst++){
			if (s[Yst][Xst] == '#'){
				continue;
			}
			//cout << "Yst : " << Yst << ", Xst : " << Xst << endl;
			queue<pair<int, int> > que;
			//memset(distance, MM, sizeof(dist));
			for (int y = 0; y < H; y++){
				for (int x = 0; x < W; x++){
					distance[y][x] = MM;
				}
			}
			p.first = Yst; p.second = Xst;
			que.push(p);
			distance[Yst][Xst] = 0;
			while (que.size()){
				pair<int, int> cur = que.front();
				que.pop();
				for (int i = 0; i < 4; i++){
					int ny = cur.first + dy[i];
					int nx = cur.second + dx[i];
					if (0 <= ny && ny < H && 0 <= nx && nx < W){
						if (s[ny][nx] == '#'){
							continue;
						}
						if (distance[ny][nx] <= distance[cur.first][cur.second] + 1){
							continue;
						}
						distance[ny][nx] = distance[cur.first][cur.second] + 1;
						p.first = ny; p.second = nx;
						que.push(p);
						maxDist = max(maxDist, distance[ny][nx]);
					}
				}
			}
		}
	}
	cout << maxDist << endl;
}




Measured memory_bytes: 256