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: Wrong Answer)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll cfmod = 998244353;
const int MAXN = 5 * 1e5+5;


string s1, s2;

int cont[MAXN], ac[MAXN], l, c;
char m[25][25];
int dist[25][25];

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

int ans = 0;

void bfs(pii a) {
	queue<pii> fila;
	fila.push(a);
	for(int i = 0; i < l; i++)
		for(int j = 0; j < c; j++)
			dist[i][j] = INF;
			
	dist[a.f][a.s] = 0;
	
	while(!fila.empty()) {
		pii atual = fila.front();
		ans = max(ans, dist[atual.f][atual.s]);
		fila.pop();
		
		for(int i = 0; i < 4; i++) {
			int ni = atual.f + x[i], nj = atual.s + y[i];
			if(ni < 0 or ni >= l or nj < 0 or nj >= c or m[ni][nj] == '#') continue;
			if(dist[atual.f][atual.s] + 1 < dist[ni][nj]) {
				dist[ni][nj] = dist[atual.f][atual.s]+1;
				fila.push({ni, nj});
			}
		}
	}
}

int32_t main() {
	cin >> l >> c;
	
	for(int i = 0; i < l; i++)
		for(int j = 0; j < c; j++)
			cin >> m[i][j];
	
	for(int i = 0; i < l; i++)
		for(int j = 0; j < c; j++)
			bfs({i, j});
			
	cout << ans << endl;
}