#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

ll solve(vector<string> &s, ll start_h, ll start_w) {
    ll h = s.size(), w = s[0].size();

    ll distance[h][w];
    rep(i, h) {
        rep(j, w) { distance[i][j] = -1; }
    }

    distance[start_h][start_w] = 0;

    queue<pair<ll, ll>> q;
    q.push(make_pair(start_h, start_w));

    ll ans = 0;
    while (!q.empty()) {
        pair<ll, ll> p = q.front();
        q.pop();
        ll index0[4] = {-1, 0, 1, 0};
        ll index1[4] = {0, 1, 0, -1};
        rep(i, 4) {
            ll point_h = p.first + index0[i], point_w = p.second + index1[i];
            if ((point_h < 0 | h <= point_h) | (point_w < 0 | w <= point_w)) {
                continue;
            }
            if (s[point_h][point_w] == '#') {
                continue;
            }

            if (distance[point_h][point_w] >= 0) {
                continue;
            }

            ll num = distance[p.first][p.second];
            distance[point_h][point_w] = num + 1;
            ans = max(ans, num + 1);
            q.push(make_pair(point_h, point_w));
        }
    }

    /*
        cout << start_h << " " << start_w << endl;
        rep(i, h) {
            rep(j, w) { cout << distance[i][j]; }
            cout << endl;
        }
    */

    return ans;
}

int main() {
    // source
    ll h, w;
    cin >> h >> w;

    vector<string> s(h);
    rep(i, h) { cin >> s[i]; }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) { ans = max(ans, solve(s, i, j)); }
    }

    cout << ans << endl;
    return 0;
}

