#include <bits/stdc++.h>

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n,m;
    cin>>n>>m;

    vector <vector <char> > a(n,vector <char>(m));
    loop(i,0,n)
    {
        loop(j,0,m)
        {
            cin>>a[i][j];
        }
    }

    int ans=ninf;
    loop(i,0,n)
    {
        loop(j,0,m)
        {
            if(a[i][j]=='.')
            {
                loop(x,0,n)
                {
                    loop(y,0,m)
                    {
                        if(a[x][y]=='.')
                        {
                            queue <pair <int,int> > q;
                            vector <vector <int> > dist(n,vector <int>(m,-1));
                            vector <vector <int> > vis(n,vector <int>(m,false));
                            loop(u,0,n)
                            {
                                loop(v,0,m)
                                {
                                    if(a[u][v]=='#')
                                    {
                                        vis[u][v]=true;
                                    }
                                    else
                                        vis[u][v]=false;
                                }
                            }
                            dist[i][j]=0;
                            vis[i][j]=true;
                            q.push({i,j});

                            while(not q.empty())
                            {
                                pair <int,int> pr=q.front();
                                q.pop();

                                int u=pr.first;
                                int v=pr.second;

                                // down
                                if(u+1<n and not vis[u+1][v])
                                {
                                    q.push({u+1,v});
                                    dist[u+1][v]=dist[u][v]+1;
                                    vis[u+1][v]=true;
                                }
                                if(u-1>=0 and not vis[u-1][v])
                                {
                                    q.push({u-1,v});
                                    dist[u-1][v]=dist[u][v]+1;
                                    vis[u-1][v]=true;
                                }
                                if(v+1<m and not vis[u][v+1])
                                {
                                    q.push({u,v+1});
                                    dist[u][v+1]=dist[u][v]+1;
                                    vis[u][v+1]=true;
                                }
                                if(v-1>=0 and not vis[u][v-1])
                                {
                                    q.push({u,v-1});
                                    dist[u][v-1]=dist[u][v]+1;
                                    vis[u][v-1]=true;
                                }
                            }
                            if(dist[x][y]!=-1)
                            {
                                ans=max(ans,dist[x][y]);
                            }
                        }
                    }
                }
            }
        }
    }



    cout<<ans;
    return 0;
}


Measured memory_bytes: 3624