/*  Author:  Hariom_Pandey
    Created: 1/12/2020 6:10:04 PM
*/
#include "bits/stdc++.h"
using namespace std;
#define Hariom_Pandey  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define All(a)          (a).begin(), (a).end()
#define Sort(x)         sort(All(x))
#define Unique(v)       Sort(v); (v).resize(unique(All(v)) - (v).begin())
const int N = 1e6 + 5;
const int wx[4]={0,0,1,-1},wy[4]={1,-1,0,0};
int n,m;
bool map[21][21];
bool walk[21][21];
int max(int a,int b)
{
    if(a>b) return a;
    return b;
}
struct Node {
    int x,y,deep;
}q[100000];
int bfs(int x,int y)
{
    memset(walk,0,sizeof(walk));
    q[1].x=x,q[1].y=y,q[1].deep=0;
    walk[x][y]=1;
    int l=1,r=1;
    while(l<=r)
    {
        for(int i=0;i<4;++i)
        {
            int tx=q[l].x+wx[i],ty=q[l].y+wy[i];
            if(map[tx][ty]==1||walk[tx][ty]==1||tx<=0||ty<=0||tx>n||ty>m) continue;
            q[++r].x=tx,q[r].y=ty;
            q[r].deep=q[l].deep+1;
            walk[tx][ty]=1;
        }
        ++l;
    }
   
    return q[r].deep;
}
int main()
{
    scanf("%d%d",&n,&m);
    char ch;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            cin>>ch;
            if(ch=='#') map[i][j]=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(map[i][j]==0) ans=max(ans,bfs(i,j));
        }
    }
    printf("%d",ans);
}