#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int,int> P;
int INF = -1000000;

int main() {
    int H,W;cin >> H >> W;
    char s[H][W] = {};
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            cin >> s[i][j];
        }
    }
    int sx,sy;
    queue<P> que;
    int d[H][W] = {};
    int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
    int res = 0;
    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++) {
                    d[k][l] = INF;
                }
            }

            sy = i;sx = j;
            que.push(P(sy,sx));
            d[sy][sx] = 0;

            while (que.size()){
                P p = que.front();que.pop();
                for (int i = 0;i < 4;i++){
                    int ny = p.first + dy[i];int nx = p.second + dx[i];
                    if (nx >= 0 && nx < W && ny >= 0 && ny < H && s[ny][nx] != '#' && d[ny][nx] == INF){
                        d[ny][nx] = d[p.first][p.second] + 1;
                        que.push(P(ny,nx));
                    }
                }
            }

            for (int k = 0;k < H;k++) {
                for (int l = 0; l < W; l++) {
                    res = max(res,d[k][l]);
                }
            }
        }
    }
    cout << res << endl;
}