#include<bits/stdc++.h>
using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;

#define sf                  scanf
#define pf                  printf
#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define PF                  first
#define PS                  second
#define si(n)               scanf("%d",&n)
#define sii(x,y)            scanf("%d %d",&x,&y)
#define siii(x,y,z)         scanf("%d %d %d",&x,&y,&z)
#define sl(n)               scanf("%lld",&n)
#define sll(x,y)            scanf("%lld %lld",&x,&y)
#define slll(x,y,z)         scanf("%lld %lld %lld",&x,&y,&z)
#define FOR(i,x,y)          for(int i=x;i<y;i++)
#define RFOR(i,x,y)         for(int i=x;i>=y;i--)
#define CLR(arr,val)        memset(arr,val,sizeof arr);
#define vout(v)             for(int ind=0;ind<v.size();ind++){ cout<<v[ind]; if(ind<v.size()-1) cout<<' '; else cout<<endl;}
#define TCL(test,t)         for(test=1;test<=t;test++)
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("input.txt", "w", stdout)
#define fastIO()            {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define MAXN                100005
#define MOD                 1000000000
#define PI                  acos(-1)

int fl[30][30][30][30],maze[30][30];
string s[50];

int main(){
    int n,m,x,y;
    cin>>n>>m;
    CLR(maze,-1);
    for(int i=0;i<n;i++){
        cin>>s[i];
        for(int j=0;j<m;j++){
            if(s[i][j]=='.'){
                maze[i+1][j+1]=0;
                x=i+1; y=j+1;
            }
        }
    }
    for(int i=0;i<=n+1;i++){
        for(int j=0;j<=m+1;j++){
            for(int k=0;k<=n+1;k++){
                for(int l=0;l<=m+1;l++){
                    fl[i][j][k][l]=MAXN;
                }
            }
            fl[i][j][i][j]=0;
        }
        fl[i][i][i][i]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!maze[i][j]&&!maze[i+1][j]){
                fl[i][j][i+1][j]=1;
                fl[i+1][j][i][j]=1;
            }
            if(!maze[i][j]&&!maze[i-1][j]){
                fl[i][j][i-1][j]=1;
                fl[i-1][j][i][j]=1;
            }
            if(!maze[i][j]&&!maze[i][j+1]){
                fl[i][j][i][j+1]=1;
                fl[i][j+1][i][j]=1;
            }
            if(!maze[i][j]&&!maze[i][j-1]){
                fl[i][j][i][j-1]=1;
                fl[i][j-1][i][j]=1;
            }
        }
    }
    for(int kx=1;kx<=n;kx++){
        for(int ky=1;ky<=m;ky++){
            for(int ix=1;ix<=n;ix++){
                for(int iy=1;iy<=m;iy++){
                    for(int jx=1;jx<=n;jx++){
                        for(int jy=1;jy<=m;jy++){
                            fl[ix][iy][jx][jy]=min(fl[ix][iy][jx][jy],fl[ix][iy][kx][ky]+fl[kx][ky][jx][jy]);
                        }
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            for(int k=1;k<=n;k++){
                for(int l=1;l<=m;l++){
                    if(fl[i][j][k][l]<MAXN){
                        ans=max(ans,fl[i][j][k][l]);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2048