#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) char a[n + 3][m + 3] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e12;
const ll mod = 1e9 + 7;
vi adj[401];
int n, m;
inline int coo (int i, int j) {return (i - 1)*m + j;}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int d[401][401] = {};
	
    cin >> n >> m;
    READMAT(a, n, m);
    FOR (i, 1, n)
        FOR (j, 1, m)
        {
            if (a[i][j] == '#') continue;
            if (a[i + 1][j] == '.') d[coo(i, j)][coo(i + 1, j)] = d[coo(i + 1, j)][coo(i, j)] = 1;
            if (a[i - 1][j] == '.') d[coo(i, j)][coo(i - 1, j)] = d[coo(i - 1, j)][coo(i, j)] = 1;
            if (a[i][j + 1] == '.') d[coo(i, j)][coo(i, j + 1)] = d[coo(i, j + 1)][coo(i, j)] = 1;
            if (a[i][j - 1] == '.') d[coo(i, j)][coo(i, j - 1)] = d[coo(i, j - 1)][coo(i, j)] = 1;
        }
    
    FOR (i, 1, 400)
        FOR (j, 1, 400)
            if (!d[i][j]) d[i][j] = inf;
            
    int ans = 0;
    
    for (int k = 1; k <= 400; ++k) {
       for (int i = 1; i <= 400; ++i) {
        for (int j = 1; j <= 400; ++j) {
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
    }
    FOR (i, 1, 400)
        FOR (j, 1, 400)
            if ((d[i][j] < inf) && d[i][j]) ans = max(ans, d[i][j]);
    
    cout << ans;
}