#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int h, w;
	cin >> h >> w;
	string s[h];
	for(int i = 0; i < h; i++) {
		cin >> s[i];
	}
	int ans = -1;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(s[i][j] == '.') {
				for(int k = 0; k < h; k++) {
					for(int l = 0; l < w; l++) {
						if(s[k][l] == '.') {
							bool vis[h][w];
							int val[h][w];
							memset(vis, 0, sizeof(vis));
							memset(val, 0, sizeof(val));
							queue<pii> q;
							q.push({i, j});
							vis[i][j] = 0;
							while(!q.empty()) {
								int ti = q.front().fi, tj = q.front().se;
								q.pop();
								for(int tt = 0; tt < 4; tt++) {
									if(ti + dx[tt] >= 0 && ti + dx[tt] < h && tj + dy[tt] >= 0 && tj + dy[tt] < w && s[ti + dx[tt]][tj + dy[tt]] == '.' && !vis[ti + dx[tt]][tj + dy[tt]]) {
										q.push({ti + dx[tt], tj + dy[tt]});
										vis[ti + dx[tt]][tj + dy[tt]] = 1;
										val[ti + dx[tt]][tj + dy[tt]] = val[ti][tj] + 1;
									}
								}
							}
							ans = max(ans, val[k][l]);
						}
					}
				}
			}
		}
	}
	cout << ans;

	return 0;
}