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


struct Object {
    int  x;
    int  y;
    int sum;
};

const int yvec[4] = {0, 0, -1, 1};
const int xvec[4] = {-1, 1, 0, 0};

int bfs(Object st) {
    queue<Object> q;
    q.push(st);
    sum1 = 0;
    while(!q.empty()) {
        Object now = q.front(); q.pop();
        x_1 = now.x;
        y_1 = now.y;
        sum1 = now.sum;
        
        
        for(int i = 0; i < 4; i++) {
            Object next = { x_1 + xvec[i], y_1 + yvec[i], sum1 + 1};
            if(0 <= next.y && next.y <= H - 1 && 0 <= next.x && next.y <= W - 1 && vec[next.y][next.x] == '.') {
                S[next.y][next.x] = 'x';
                q.push(next);
            }
        }
    
    }
    return sum1;
} 
int main() {
    
    cin >> H >> W;
    
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cin >> S[i][j];
        }
    }

     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(start)); }
        }
    }

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