#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i  = a; i < b; i++)
typedef long long ll;

static const int MAX_V = 400 * 400 + 10;
const int INF = 1e9;

int d[MAX_V][MAX_V];
int V;

void warshall_floyde(){
    for(int k = 0; k < V; k++){
        for(int i = 0; i < V; i++){
            for(int j = 0; j < V; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}


int main(){
    int H, W; cin >> H >> W;
    vector<string> S(H);
    rep(i, 0, H) cin >> S[i];
    V = H * W;
    rep(i, 0, H * W) rep(j, 0, H * W) d[i][j] = INF;

    rep(i, 0, H){
        rep(j, 0, W){
            if(S[i][j] == '.') {
                if(i - 1 >= 0 && S[i-1][j] == '.') d[W*i+j][W*(i-1)+j] = 1;
                if(i + 1 < H && S[i+1][j] == '.') d[W*i+j][W*(i+1)+j] = 1;
                if(j - 1 >= 0 && S[i][j-1] == '.') d[W*i+j][W*i+j-1] = 1;
                if(j + 1 < W && S[i][j+1] == '.') d[W*i+j][W*i+j+1] = 1;
            }
        }
    }

    warshall_floyde();

    int ans = 0;

    rep(i, 0, H * W) rep(j, 0, H * W){
        if(d[i][j] != INF) ans = max(ans, d[i][j]);
    }
    cout << ans << endl;
}