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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}

LL dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
LL co[500][500];
void WF(LL v,LL e,LL* a,LL* b,LL* l){LL i,j,k;FOR(i,1,v+1)FOR(j,1,v+1){if(i==j)co[i][j]=0;else co[i][j]=INF;}FOR(i,0,e)co[a[i]][b[i]]=l[i];FOR(k,1,v+1)FOR(i,1,v+1)FOR(j,1,v+1)co[i][j]=MIN(co[i][j],co[i][k]+co[k][j]);}

int main(){
  LL H,W,i,j,k,nx,ny,m=0,ans=0;
  scanf("%lld%lld",&H,&W);
  char S[H][W+1];
  FOR(i,0,H)scanf("%s",S[i]);
  LL a[10000],b[10000],l[10000];
  FOR(i,0,H)FOR(j,0,W)if(S[i][j]=='.')FOR(k,0,4){
    nx=i+dx[k],ny=j+dy[k];
    if(nx>=0&&nx<H&&ny>=0&&ny<W)if(S[nx][ny]=='.')
    a[m]=nx*W+ny+1,b[m]=i*W+j+1,l[m++]=1,a[m]=i*W+j+1,b[m]=nx*W+ny+1,l[m++]=1;
  }
  WF(H*W,m,a,b,l);
  FOR(i,0,H*W)FOR(j,i,H*W)if(co[i][j]!=INF)ans=MAX(ans,co[i][j]);

  printf("%lld\n",ans);
	return 0;
}