#include<bits/stdc++.h>
using namespace std;
int n,m,ans=0;
char A[21][21];
int vis[21][21];
int bfs(pair<int,int>p,int level)
{
    //int level = 0;
    //cout << "FC" << p.first << "," << p.second << "-> ";
    if (A[p.first][p.second] == '#') return 0;
    queue<pair<int, int>>q;
    q.push(p);
    //level++;
    vis[p.first][p.second] = level;
    while (!q.empty())
    {
        pair<int, int>p_t = q.front();
        
        q.pop();
        int k = vis[p_t.first][p_t.second];
        if (p_t.first+1<n and A[p_t.first + 1][p_t.second]=='.')
        {
            if (vis[p_t.first+1][p_t.second] == -1)
            {
                vis[p_t.first+1][p_t.second] = k + 1;
                level = max(level, vis[p_t.first + 1][p_t.second]);
                q.push({p_t.first+1,p_t.second});
                //cout << p_t.first << "," << p_t.second << ":" << vis[p_t.first + 1][p_t.second] << " ";
            }
        }
        if (p_t.second + 1 < m and A[p_t.first][p_t.second+1] == '.')
        {
            if (vis[p_t.first][p_t.second + 1] == -1)
            {
                vis[p_t.first][p_t.second + 1] = k + 1;
                level = max(level, vis[p_t.first][p_t.second+1]);
                q.push({ p_t.first,p_t.second+1 });
                //cout << p_t.first << "," << p_t.second << ":" << level << " ";
            }
        }
        if (p_t.first - 1 >= 0 and A[p_t.first - 1][p_t.second] == '.')
        {
            if (vis[p_t.first - 1][p_t.second] == -1)
            {
                vis[p_t.first-1][p_t.second ] = k + 1;
                level = max(level, vis[p_t.first-1][p_t.second]);
                q.push({ p_t.first-1,p_t.second });
                //cout << p_t.first << "," << p_t.second << ":" << level << " ";
            }
        }
        if (p_t.second - 1 >= 0 and A[p_t.first][p_t.second - 1] == '.')
        {
            if (vis[p_t.first][p_t.second-1] == -1)
            {
                vis[p_t.first][p_t.second-1] = k + 1;
                level = max(level, vis[p_t.first][p_t.second-1]);
                q.push({ p_t.first,p_t.second-1 });
                //cout << p_t.first << "," << p_t.second << ":" << level << " ";
            }
        }
        //cout << p_t.first << "," << p_t.second << ":" << level << " ";
    }
    return level;
}
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)for (int j = 0; j < m; j++) cin >> A[i][j];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            memset(vis, -1, sizeof(vis));
            //int level[400];
            int k = bfs({ i,j }, 0);
            ans = max(ans,k);
            //if (k == 39) cout << i << "," << j << "-"<<A[i][j]<<" ";
            //cout << "\n" << ans << "\n\n";
        }
    }
    cout << ans;
}



/*int n, m;
    int A = 0, D = 0;
    bool memo[100001];
    vector<int> num(100001,0);
    cin >> n >> m;
    int k;
    string s;
    for (int i = 0; i < m; i++)
    {
        cin >> k >> s;
        if (!memo[k])
        {
            if (s == "WA")num[k]++;
            else
            {
                A++;
                memo[k] = 1;
                D += num[k];
            }
        }
    }
    cout << A << " " << D;*/

Measured memory_bytes: 256