#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h + 2);
    s[0] = string(w + 2, '#');
    s[h + 1] = string(w + 2, '#');
    string t;
    REP1(i, h) {
        cin >> t;
        s[i] = '#' + t + '#';
    }

    int ans = 0;
    REP1(i, h) REP1(j, w) {
        if (s[i][j] == '#') continue;
        REP1(k, h) REP1(l, w) {
            if (s[k][l] == '#') continue;
            // cout << "---------" << EOL; cout << i << ":" << j << "//" << k << ":" << l << EOL;

            deque<pair<pair<int, int>, int>> q;
            q.emplace_back(i, j, 0);
            set<pair<int, int>> memo;
            memo.emplace(i, j);
            int r, c, t;
            while (!q.empty()) {
                tie(r, c, t) = q.front(); q.pop_front();
                // cout << r << ":" << c << "/" << t << EOL;

                if (r == k && c == l) {
                    chmax(ans, t);
                    break;
                }

                auto p = make_pair(r - 1, c);
                if (s[r - 1][c] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
                p = make_pair(r + 1, c);
                if (s[r + 1][c] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
                p = make_pair(r, c - 1);
                if (s[r][c - 1] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
                p = make_pair(r, c + 1);
                if (c != w - 1 && s[r][c + 1] != '#' && memo.count(p) == 0) {
                    memo.emplace(p);
                    q.emplace_back(p, t + 1);
                }
            }
        }
    }
    cout << ans << EOL;
}
