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

const int N = 22;
char C[N][N];

int h, w;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

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

    int dx[4] = {-1, 1, 0, 0};
    int dy[4] = {0, 0, -1, 1};

    int ans = 0;
    for(int sx = 0; sx < h; sx++){
        for(int sy = 0; sy < w; sy++){
            int D[h][w] = {};
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    D[i][j] = 1e9;
                }
            }
            D[sx][sy] = 0;
            queue<pair<int, int>> q;
            q.push({sx, sy});
            int ma = 0;
            while(!q.empty()){
                pair<int, int> now = q.front();
                q.pop();
                int x = now.first;
                int y = now.second;

                for(int i = 0; i < 4; i++){
                    int nx = dx[i] + x;
                    int ny = dy[i] + y;
                    if(nx < 0 or ny < 0 or nx >= h or ny >= w){
                        continue;
                    }
                    if(C[nx][ny] == '#'){
                        continue;
                    }
                    if(D[x][y] + 1 < D[nx][ny]){
                        D[nx][ny] = D[x][y] + 1;
                        ma = max(ma, D[nx][ny]);
                        q.push({nx, ny});
                    }
                }
            }
            ans = max(ans, ma);
        }
    }

    cout << ans << endl;

    return 0;
}