#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long llong;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

static const int MAX = 20;
static const int NIL = -1;
int n, m;
char s[MAX][MAX + 1];
int d[MAX][MAX + 1];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ans;

void dfs(int x, int y, int k){
    REP(l, n){
        REP(g, m){
            d[l][g] = NIL;
        }
    }
    queue <pair<int, int> > S;
    S.push(make_pair(x, y));
    d[x][y] = 0;
    if (k == 1) s[x][y] = '#';
    int maxL = 0;
    int maxX = x;
    int maxY = y;
    while (!S.empty()){
        int X = S.front().first;
        int Y = S.front().second;
        S.pop();
        REP(l, 4){
            int nx = X + dx[l];
            int ny = Y + dy[l];
            if (0 <= nx && nx < n && 0 <= ny && ny < m && s[nx][ny] != '#' && d[nx][ny] == NIL){
                if (k == 1) s[nx][ny] = '#';
                S.push(make_pair(nx, ny));
                d[nx][ny] = d[X][Y] + 1;
                if (maxL < d[nx][ny]){
                    maxL = d[nx][ny];
                    maxX = nx;
                    maxY = ny;
                }
            }
        }
    }
    ans = max(ans, maxL);
    if (k == 1) dfs(maxX, maxY, k + 1);
}

int main(){
    cin >> n >> m;
    REP(i, n){
        REP(j, m){
            cin >> s[i][j];
        }
    }

    int cnt = 0;
    ans = 0;
    int h, w;
    REP(i, n){
        REP(j, m){
            if (s[i][j] == '.'){
                h = i:
                w = j;
            }
        }
    }
    dfs(h, w, 0);
    cout << ans << endl;
    return 0;
}