#include <iostream>
#include <stack>
#include <vector>
using namespace std;

int main()
{
    int h,w;
    cin >> h >> w;
    char m[h][w] = {};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> m[i][j];
        }
    }
    
    int ans = 0;
    vector<pair<int,int>> dv = {{-1,0}, {1,0}, {0,-1}, {0,1}};
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(m[i][j] != '.') continue;
            stack<pair<int,int>> st;
            vector<vector<int>> rec(h, vector<int>(w, -1));
            st.push({i,j});
            rec[i][j] = 0;
            while(!st.empty()){
                auto n = st.top();
                st.pop();
                for(auto d: dv){
                    int x = n.first + d.first;
                    int y = n.second + d.second;
                    if(x < 0 || x >= h || y < 0 || y >= w) continue;
                    if(m[x][y] != '.') continue;
                    if(rec[x][y] >= 0) continue;
                    st.push({x,y});
                    rec[x][y] = rec[n.first][n.second] + 1;
                }
            }
            int ma = 0;
            for(int ii=0; ii<h; ii++) 
                for(int jj=0; jj<w; jj++){
                    ma = max(ma, rec[ii][jj]);
                }
            ans = max(ans, ma);
        }
    }
    cout << ans << endl;
    return 0;
}