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>
using namespace std;

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vs = V<string>;

const int INF = 1999999999;

const int DX[4]= {-1,0,1,0};
const int DY[4]= {0,-1,0,1};

template<typename T>
T SUM(V<T> v, T init_val=0){return accumulate(ALL(v),T(init_val));}

int main(){
    int h,w;
    cin>>h>>w;
    Vs s(h);
    REP(i,h){
        cin>>s[i];
    }

    V<Vi> dist(h*w,Vi(h*w,INF/2));
    REP(i,h*w){dist[i][i]=0;}

    REP(y,h){
        REP(x,w){
            REP(i,4){
                int dx = x + DX[i];
                int dy = y + DY[i];
                if(dx<0 || w<=dx) continue;
                if(dy<0 || h<=dy) continue;
                if(s[dy][dx] == '#') continue;
                dist[y*w+x][dy*w+dx] = 1;
            }
        }
    }

    REP(k,h*w){REP(i,h*w){REP(j,h*w){dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);}}}

    int ans=0;
    REP(i,h*w){
        REP(j,h*w){
            if(dist[i][j] == INF/2) continue;
            ans = max(ans,dist[i][j]);
        }
    }

    cout<<ans<<endl;

    return 0;
}