Problem:
Score : 400 points

Problem Statement

Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.

The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is ..

From a road square, you can move to a horizontally or vertically adjacent road square.

You cannot move out of the maze, move to a wall square, or move diagonally.

Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.

Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.

In this situation, find the maximum possible number of moves Aoki has to make.

Constraints

1 \leq H,W \leq 20

S_{ij} is . or #.

S contains at least two occurrences of ..

Any road square can be reached from any road square in zero or more moves.

Input

Input is given from Standard Input in the following format:

H W
S_{11}...S_{1W}
:
S_{H1}...S_{HW}

Output

Print the maximum possible number of moves Aoki has to make.

Sample Input 1

3 3
...
...
...

Sample Output 1

4

If Takahashi chooses the top-left square as the starting square and the bottom-right square as the goal square, Aoki has to make four moves.

Sample Input 2

3 5
...#.
.#.#.
.#...

Sample Output 2

10

If Takahashi chooses the bottom-left square as the starting square and the top-right square as the goal square, Aoki has to make ten moves.

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;


template<typename T>
void dump(T *arr, int h, int w){
	rep(i,h){
		rep(j,w) cout << arr[i][j] << "\t";
		cout << "\n";
	}
}

template<typename T>
void dump(T *arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

template<typename T>
void dump(vector<T> arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

const int INF = 1e9;
const int MOD = 1e9+7;

bool compare(P a, P b){
	if(a.second != b.second) return a.second > b.second;
	else	return a.first > b.first;
}


int digits(ll num){
	ll d=0;
	while(num >= 1){
		num/= 10;
		d++;
	}
	return d;
}

ll pow_kai(ll a, int n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int h, w;
	cin >> h >> w;

	char s[h][w];
	rep(i, h) rep(j, w) cin >> s[i][j];

	int ans=0;
	queue<tuple<int, int, int>> q;
	int hh, ww, d;
	rep(i, h) rep(j, w){
		if(s[i][j] == '#') continue;
		q.push(make_tuple(i, j, 0));
		bool visited[h][w] = {};
		int most_distant = 0;
		while(!q.empty()){
			tie(hh, ww, d) = q.front();
			q.pop();
			//auto t = q.front();
			//int hh = get<0>(t), ww=get<1>(t), d=get<2>(t);
			most_distant = max(most_distant, d);
			visited[hh][ww] = true;
			if(hh != 0 && (!visited[hh-1][ww]) && s[hh-1][ww] == '.') q.push(make_tuple(hh-1, ww, d+1));
			if(hh != h-1 && (!visited[hh+1][ww]) && s[hh+1][ww] == '.') q.push(make_tuple(hh+1, ww, d+1));
			if(ww != 0 && (!visited[hh][ww-1]) && s[hh][ww-1] == '.')q.push(make_tuple(hh, ww-1, d+1));
			if(ww != w-1 && (!visited[hh][ww+1]) && s[hh][ww+1] == '.') q.push(make_tuple(hh, ww+1, d+1));
		}
		ans = max(ans, most_distant);
	}

	cout << ans << "\n";
		
	return 0;
}