// Author: πα

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

const int N = 22;
char g[N][N];
long dp[N][N];
bool vis[N][N];

void dfs(int x, int y, long k = 0)
{
    if(vis[x][y] or g[x][y] != '.' or dp[x][y] == k)
        return;
    vis[x][y] = 1;
    dp[x][y] = min(dp[x][y], k);
    dfs(x+1, y, k+1);
    dfs(x-1, y, k+1);
    dfs(x, y+1, k+1);
    dfs(x, y-1, k+1);
    vis[x][y] = 0;
}

int main()
{
    int n, m;
    long ans = 0;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> g[i]+1;
    for(int x = 1; x <= n; ++x)
        for(int y = 1; y <= m; ++y)
            if(g[x][y] == '.')
            {
                memset(dp, -1, sizeof(dp));
                dfs(x, y);
                for(int i = 1; i <= n; ++i)
                    for(int j = 1; j <= m; ++j)
                        if(g[i][j] == '.')
                            ans = max(ans, dp[i][j]);          
            }
    cout << ans;
    return 0;
}
