#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vector<string> board;
ll h, w;

ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, -1, 0, 1};

ll find_longest(ll sx, ll sy) {
    ll max_num = 0;
    vvll costs(h, vll(w, -1));
    costs[sy][sx] = 0;
    priority_queue<pair<ll, pair<ll, ll>>> q;
    q.push(make_pair(0, make_pair(sx, sy)));

    while (q.size()) {
        auto item = q.top(); q.pop();
        ll x = item.second.first;
        ll y = item.second.second;
        ll cost = item.first;

        costs[y][x] = cost;

        rep(i, 4) {
            ll nx = x + dx[i];
            ll ny = y + dy[i];

            if (
                0 <= nx && 
                nx < w && 
                0 <= ny && 
                ny < h && 
                board[ny][nx] == '.' && 
                (costs[ny][nx] == -1)
            ) q.push(make_pair(cost + 1, make_pair(nx, ny))), max_num = max(max_num, cost + 1); 
        }
    }

    return max_num;
}

int main()
{
    cin >> h >> w;
    board.resize(h);
    ll max_num = 0;
    rep(i, h) cin >> board[i];
    rep(i, h) rep(j, w) {
        if (board[i][j] == '#') continue;
        max_num = max(max_num, find_longest(j, i));
    }
    cout << max_num << endl;
    return 0;
}