#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define h_max 20000

vector<vector<int>> dist(30, vector<int>(30, 30*30));
vector<vector<int>> stamp(30, vector<int>(30, 0));
vector<vector<int>> s(30, vector<int>(30, 1));
int h;
int w;

void bfs(int h0, int w0){
    pair<int, int> tmp_hw;
    queue<pair<int, int>> q;
    tmp_hw.first=h0;
    tmp_hw.second=w0;
    q.push(tmp_hw);
    int h1;
    int w1;
    while(!q.empty()){
        tmp_hw=q.front(); q.pop();
        h0=tmp_hw.first;
        w0=tmp_hw.second;
        h1=h0-1;
        w1=w0;
        if(h1>=0 && h1<h){
            if(w1>=0 && w1<w){
                if(s[h1][w1]==0 && stamp[h1][w1]==0){
                    dist[h1][w1]=dist[h0][w0]+1;
                    stamp[h1][w1]=1;
                    tmp_hw.first=h1;
                    tmp_hw.second=w1;
                    q.push(tmp_hw);
                }
            }
        }
        h1=h0+1;
        w1=w0;
        if(h1>=0 && h1<h){
            if(w1>=0 && w1<w){
                if(s[h1][w1]==0 && stamp[h1][w1]==0){
                    dist[h1][w1]=dist[h0][w0]+1;
                    stamp[h1][w1]=1;
                    tmp_hw.first=h1;
                    tmp_hw.second=w1;
                    q.push(tmp_hw);
                }
            }
        }
        h1=h0;
        w1=w0-1;
        if(h1>=0 && h1<h){
            if(w1>=0 && w1<w){
                if(s[h1][w1]==0 && stamp[h1][w1]==0){
                    dist[h1][w1]=dist[h0][w0]+1;
                    stamp[h1][w1]=1;
                    tmp_hw.first=h1;
                    tmp_hw.second=w1;
                    q.push(tmp_hw);
                }
            }
        }
        h1=h0;
        w1=w0+1;
        if(h1>=0 && h1<h){
            if(w1>=0 && w1<w){
                if(s[h1][w1]==0 && stamp[h1][w1]==0){
                    dist[h1][w1]=dist[h0][w0]+1;
                    stamp[h1][w1]=1;
                    tmp_hw.first=h1;
                    tmp_hw.second=w1;
                    q.push(tmp_hw);
                }
            }
        }
    }
}

int main() {
    int ans=0;
    int tmp_ans;
    cin >> h >> w;
    char tmp_s;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> tmp_s;
            if(tmp_s=='.'){
                s[i][j]=0;
            }else{
                s[i][j]=1;
            }
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            for(int k=0; k<h; k++){
                for(int l=0; l<w; l++){
                    dist[k][l]=30*30;
                    stamp[k][l]=0;
                }
            }
            if(s[i][j]==1)continue;
            dist[i][j]=0;
            stamp[i][j]=1;
            bfs(i,j);
            tmp_ans=0;
            for(int k=0; k<h; k++){
                for(int l=0; l<w; l++){
                    if(tmp_ans<dist[k][l] && s[k][l]==0){
                        tmp_ans=dist[k][l];
                    }
                    //cout << i << " " << j << " " << k << " " << l << " " << dist[k][l] << endl;
                }
            }
            //cout << tmp_ans << endl;
            if(tmp_ans>ans){
                ans=tmp_ans;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256