#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
int main(){
    int H, W; cin >> H >> W;
    int M[H][W];
    for(int i = 0; i < H; i++){
        string S; cin >> S;
        for(int j = 0; j < W; j++){
            if(S[j] == '.') M[i][j] = 1;
            else M[i][j] = 0;
            //cout << M[i][j];
        }
        //cout << endl;
    }
    int sh[4] = {1, 0, -1, 0};
    int sw[4] = {0, 1, 0, -1};
    int max = 0;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(M[i][j] == 0) continue;
            //cout << i << " " << j << endl;
            queue<int> qh, qw;
            int maze[H][W];
            int map[H][W];
            memset(maze, 0, sizeof(maze));
            memset(map, 0, sizeof(map));
            int sth = i; int stw = j;
            qh.push(sth); qw.push(stw); 
            map[i][j] = 1;
            while(!qh.empty()){
                
                int h = qh.front(); int w = qw.front();
                //cout << "  " << h << " " << w << endl;
                qh.pop(); qw.pop();
                for(int i = 0; i < 4; i++){
                    int nx_h = h + sh[i];
                    int nx_w = w + sw[i];
                    if(0 <= nx_h && nx_h < W && 0 <= nx_w && nx_w < W){ //範囲内なら
                      
                        if(M[nx_h][nx_w] == 1){ //障害物がないなら
                            
                             if(map[nx_h][nx_w] == 0){ //未探索か最小でいける
                                //cout << "    " << nx_h << " " << nx_w <<" " <<  maze[nx_h][nx_w] << endl;
                                qh.push(nx_h);
                                qw.push(nx_w);
                                maze[nx_h][nx_w] = maze[h][w] + 1;
                                map[nx_h][nx_w] = 1;
                                if(max < maze[nx_h][nx_w]) max = maze[nx_h][nx_w];
                             }
                        }
                    }
                }
            }
            //cout << "max   " << max << endl;
        }
    }
    //if(max >= 38) cout << 38 << endl;
    else cout << max << endl;
}