#include <bits/stdc++.h>
using namespace std;
#define int long long
#define read >>
#define echo cout <<
#define fin << '\n'
#define _ << ' ' <<
#define in :

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

string mp[22];
int dp[22][22][22][22];
int h, w;

bool ins ( int y, int x ) {
    return 0 <= y && y < h && 0 <= x && x < w;
}

void bfs ( int Y, int X ) {
    queue<pair<int, int>> q;
    dp[Y][X][Y][X] = 0;
    q.push(make_pair(Y, X));
    while ( !q.empty() ) {
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        for ( int i = 0; i < 4; i++ ) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if ( ins(ny, nx) && dp[Y][X][ny][nx] == -1 && mp[ny][nx] == '.' ) {
                q.push(make_pair(ny, nx));
                dp[Y][X][ny][nx] = dp[Y][X][y][x] + 1;
            }
        }
    }
}

signed main ( ) {

    cin >> h >> w;
    for ( int i = 0; i < h; i++ ) cin >> mp[i];

    memset(dp, -1, sizeof(dp));

    for ( int i = 0; i < h; i++ ) {
        for ( int j = 0; j < w; j++ ) {
            bfs ( i, j );
        }
    }

    int ans = 0;
#define f(i) for ( int i = 0; i < 22; i++ )
    f(i)f(j)f(k)f(l) ans = max ( ans, dp[i][j][k][l] );
#undef f
    echo ans fin;

    return 0;
}