#include<bits/stdc++.h>
#include <numeric>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

int h,w;
vector<vector<int>> ansv(25, vector<int>(25, -1));
vector<vector<char>> s(25, vector<char>(25));

int aaa[25][25][25][25];

int dp(int s_i, int s_j) {

    if(s[s_i][s_j] == '#') {
        return -1;
    }

    int n_i = s_i;
    int n_j = s_j;


    queue<pair<pair<int,int>, int>> q;

    int n_p = 0;
    aaa[s_i][s_j][n_i][n_j] = n_p;

    if(n_i > 0 && aaa[s_i][s_j][n_i-1][n_j] == -1) {
        // 上
        //dp(s_i, s_j, s_i-1, s_j, now+1);
        aaa[s_i][s_j][n_i-1][n_j] = 1;
        q.push(make_pair(make_pair(n_i-1, n_j), n_p+1));
    }
    if(n_i < h-1 && aaa[s_i][s_j][n_i+1][n_j] == -1) {
        // 下
        //dp(s_i, s_j, s_i+1, s_j, now+1);
        aaa[s_i][s_j][n_i+1][n_j] = 1;
        q.push(make_pair(make_pair(n_i+1, n_j), n_p+1));
    }
    if(n_j > 0 && aaa[s_i][s_j][n_i][n_j-1] == -1) {
        // 左
        //dp(s_i, s_j, s_i, s_j-1, now+1);
        aaa[s_i][s_j][n_i][n_j-1] = 1;
        q.push(make_pair(make_pair(n_i, n_j-1), n_p+1));
    }
    if(n_j < w-1 && aaa[s_i][s_j][n_i][n_j+1] == -1) {
        // 右
        //dp(s_i, s_j, s_i, s_j+1, now+1);
        aaa[s_i][s_j][n_i][n_j+1] = 1;
        q.push(make_pair(make_pair(n_i, n_j+1), n_p+1));
    }

    int ans = 0;
    while(!q.empty()) {

        n_i = q.front().first.first;
        n_j = q.front().first.second;
        n_p = q.front().second;
        q.pop();

        if(s[n_i][n_j] != '#') {

            chmax(ans, n_p);

            if(n_i > 0 && aaa[s_i][s_j][n_i-1][n_j] == -1) {
                // 上
                //dp(s_i, s_j, s_i-1, s_j, now+1);
                aaa[s_i][s_j][n_i-1][n_j] = 1;
                q.push(make_pair(make_pair(n_i-1, n_j), n_p+1));
            }
            if(n_i < h-1 && aaa[s_i][s_j][n_i+1][n_j] == -1) {
                // 下
                //dp(s_i, s_j, s_i+1, s_j, now+1);
                aaa[s_i][s_j][n_i+1][n_j] = 1;
                q.push(make_pair(make_pair(n_i+1, n_j), n_p+1));
            }
            if(n_j > 0 && aaa[s_i][s_j][n_i][n_j-1] == -1) {
                // 左
                //dp(s_i, s_j, s_i, s_j-1, now+1);
                aaa[s_i][s_j][n_i][n_j-1] = 1;
                q.push(make_pair(make_pair(n_i, n_j-1), n_p+1));
            }
            if(n_j < w-1 && aaa[s_i][s_j][n_i][n_j+1] == -1) {
                // 右
                //dp(s_i, s_j, s_i, s_j+1, now+1);
                aaa[s_i][s_j][n_i][n_j+1] = 1;
                q.push(make_pair(make_pair(n_i, n_j+1), n_p+1));
            }
        }
    }

    return ans;
}

int main() {

    rep(i, 25) rep(j, 25) rep(k, 25) rep(l, 25) {
        aaa[i][j][k][l] = -1;
    }

    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> s[i][j];

    int ans = 0;
    rep(i, h) rep(j, w) {
        int tmp = dp(i, j);
        chmax(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792