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: Accepted)

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}






bool vis[25][25];
int dist[25][25];
int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int main()
{
     int h,w;
     cin>>h>>w;
     char name[h+1][w+1];
     for(int i=1;i<=h;i++){
          for(int j=1;j<=w;j++){
               cin>>name[i][j];
          }
     }
     int mx=0;
     for(int i=1;i<=h;i++)
     {
          for(int j=1;j<=w;j++){
               if(name[i][j]=='#')continue;
               queue<pi> q;
               q.push({i,j});
               memset(vis,0,sizeof(vis));memset(dist,0,sizeof(dist));
               dist[i][j]=0;
               vis[i][j]=1;
               while(!q.empty())
               {
                    int x=q.front().fi,y=q.front().se;q.pop();
                    for(int k=0;k<4;k++)
                    {
                         int nx=x+dx[k],ny=y+dy[k];
                         if(nx<1||nx>h||ny<1||ny>w||name[nx][ny]=='#')continue;
                         if(!vis[nx][ny]){
                              dist[nx][ny]=dist[x][y]+1;
                              mx=max(mx,dist[nx][ny]);
                              vis[nx][ny]=1;
                              q.push({nx,ny});
                         }
                    }

               }

          }
     }
     cout<<mx;
}