#include<bits/stdc++.h>
using namespace std;

int h, w;
char maze[20][20];
bool visited[20][20]={};

isValid(int x, int y){
    return (x>=0 && x<h && y>=0 && y<w && maze[x][y]=='.' && !visited[x][y]);
}

int solve(int x, int y){

    int count = 0;

    queue<pair<int,pair<int,int>>> q;
    visited[x][y] = true;
    q.push({0,{x,y}});
    bool flag = false;

    while(!q.empty()){

        pair<int,int> t = q.front().second;
        int dist = q.front().first;
        q.pop();

        flag=false;
        if(isValid(t.first+1, t.second)){
            visited[t.first+1][t.second]=true;
            q.push({dist+1,{t.first+1, t.second}});
            count = max(count, dist+1);
        }
        if(isValid(t.first-1, t.second)){
            visited[t.first-1][t.second]=true;
            flag =true;
            q.push({dist+1,{t.first-1, t.second}});
            count = max(count, dist+1);
        }
        if(isValid(t.first, t.second-1)){
            visited[t.first][t.second-1]=true;
            flag =true;
            q.push({dist+1,{t.first, t.second-1}});
            count = max(count, dist+1);
        }
        if(isValid(t.first, t.second+1)){
            visited[t.first][t.second+1]=true;
            flag =true;
            q.push({dist+1,{t.first, t.second+1}});
            count = max(count, dist+1);
        }

    }
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            visited[i][j]=false;
        }
    }
    return count;
}

int main(){

    cin >> h >> w;

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> maze[i][j];
        }
    }

    int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(maze[i][j]=='.'){
                ans = max(ans, solve(i,j));
            }
        }
    }

    cout << ans << '\n';

    return 0;
}
