#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int x1,y1,H,W,s_x,s_y,g_y,g_x,sum1;
char S[20][20];
int sum1 = 0;

struct Object {
    int  x;
    int  y;
    int sum;
}
queue<Object> q;

vector<int> y_vec = {0, 0, -1, 1};
vector<int> x_vec = {-1, 1, 0, 0};
int bfs() {
    while(!q.empty()) {
        Object now = q.front(); q.pop();
        x1 = now.x;
        y1 = now.y;
        sum1 = now.sum;
        if(x1 == g_x && y1 == g_y) return sum1;
        
        for(int i = 0; i < 4; i++) {
            Object next = { x1 + x_vec[i], y1 + y_vec[i], sum1 + 1};
            if(0 <= next.y && next.y <= H - 1 && 0 <= next.x && next.y <= W - 1 && vec[next.y][next.x] == '.') {
                vec[next.y][next.x] = 'x';
                q.push(next);
            }
        }
    
    }
    return 0;
} 
int main() {
    
    cin >> H >> W;
    

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
           if(S[i][j] == '.' ){
            Object start = { i, j, 0 }; 
            ans = max(ans, bfs()); }
        }
    }

    cout << ans << endl;
    return 0;
}