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<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
#define N 1000000
#define O -2
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int ans=0;
int q[21][21];
int h;
int w;
void f(int x, int y) {
	if(x<h){
      if (q[x + 1][y] >= q[x][y]) {
		q[x + 1][y] = q[x][y] + 1;
		f(x + 1, y);
	}
    }
	if(y<w){
      if (q[x][y + 1] >= q[x][y]) {
		q[x][y + 1] = q[x][y] + 1;
		f(x, y + 1);
	}
    }
	if(x>=0){
      if (q[x - 1][y] >= q[x][y]) {
		q[x - 1][y] = q[x][y] + 1;
		f(x - 1, y);
	}
    }
	if(y>=0){
      if (q[x][y - 1] >= q[x][y]) {
		q[x][y - 1] = q[x][y] + 1;
		f(x, y - 1);
	}
    }
  ans=max(ans,q[x][y]);
}

int main(void){
  scanf("%d %d",&h,&w);
  char s[30][30];
  FOR(h)scanf("%s",s[i]);
  FOR(h){
    FORJ(w){
      if(s[i][j]=='.'){
        for(int x=0;x<h;x++){
          for(int y=0;y<w;y++){
            if(s[x][y]=='.'){
              q[x][y]=N;
            }else{
              q[x][y]=O;
            }
          }
        }
        q[i][j]=0;
        f(i,j);
        for(int x=0;x<h;x++){
          for(int y=0;y<w;y++)printf("%d ",q[x][y]);
          PRS("");
        }
        PRS("");
      }
    }
  }
  PRN(ans);
  return 0;
}