var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
var input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);
var input_i = -1;
var tn = function () { input_i++; return Number(input[input_i]); };
var tnn = function (n) { var a = []; for (var i = 0; i < n; i++) {
    a.push(tn());
} return a; };
var ts = function () { input_i++; return String(input[input_i]); };
var tss = function (n) { var a = []; for (var i = 0; i < n; i++) {
    a.push(ts());
} return a; };
var to = function () {
    var arg = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        arg[_i] = arguments[_i];
    }
    console.log.apply(console, arg);
};
var abs = function (a) { return Math.abs(a); };
var min = function () {
    var a = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        a[_i] = arguments[_i];
    }
    return Math.min.apply(Math, a);
};
var max = function () {
    var a = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        a[_i] = arguments[_i];
    }
    return Math.max.apply(Math, a);
};
var floor = function (a) { return Math.floor(a); };
var ceil = function (a) { return Math.ceil(a); };
var asc = function (ar) { var t = __spreadArrays(ar); return ar.sort(function (a, b) { return a - b; }); };
var desc = function (ar) { var t = __spreadArrays(ar); return t.sort(function (a, b) { return b - a; }); };
var sw = function (a, arr, op) {
    if (op === void 0) { op = '=='; }
    for (var i = 0; i < arr.length - 1; i += 2) {
        if (eval(a + op + arr[i])) {
            return arr[i + 1];
        }
    }
    return arr[arr.length - 1];
};
var near = function (n, arr) { var ne = arr[0], ni = 0; for (var i = 1; i < arr.length; i++) {
    if (Math.abs(n - ne) > Math.abs(n - arr[i])) {
        ne = arr[i];
        ni = i;
    }
} return ni; };
var deduplicate = function (a) { return Array.from(new Set(a)); };
var gcd = function (x, y) {
    var _a;
    while (y) {
        _a = [y, x % y], x = _a[0], y = _a[1];
    }
    return x;
};
var sum = function (arr) { return arr.reduce(function (a, b) { return a + b; }); };
var isPrime = function (n) { if (n < 2)
    return false; var suq = Math.sqrt(n); for (var i = 2; i <= suq; i++) {
    if (n % i == 0) {
        return false;
    }
} return true; };
var main = function () {
    var _a = tnn(2), mh = _a[0], mw = _a[1], map = new Array(mh), save = new Array(mh);
    var start = [-1];
    var dh = [0, 0, -1, 1];
    var dw = [1, -1, 0, 0];
    for (var i = 0; i < mh; i++) {
        map[i] = ts().split('');
        save[i] = new Array(mw);
        save[i].fill(600);
        // 開始位置探す
        if (start[0] == -1) {
            for (var j = 0; j < mw; j++) {
                if (map[i][j] == '.') {
                    start = [i, j];
                    break;
                }
            }
        }
    }
    // 縦,横,カウンタ
    var stack = [[start[0], start[1], 1]];
    save[start[0]][start[1]] = 0;
    var maxnum = [0, start[0], start[1]];
    while (stack.length > 0) {
        var _b = stack.pop(), h = _b[0], w = _b[1], c = _b[2];
        if (save[h][w] > maxnum[0]) {
            maxnum = [save[h][w], h, w];
        }
        for (var i = 0; i < 4; i++) {
            if (h + dh[i] < 0 || h + dh[i] >= mh || w + dw[i] < 0 || w + dw[i] >= mw)
                continue;
            if (map[h + dh[i]][w + dw[i]] == '#')
                continue;
            if (save[h + dh[i]][w + dw[i]] >= c) {
                stack.push([h + dh[i], w + dw[i], c + 1]);
                save[h + dh[i]][w + dw[i]] = c;
            }
        }
    }
    for (var i = 0; i < mh; i++) {
        save[i].fill(600);
    }
    start = [maxnum[1], maxnum[2]];
    stack = [[start[0], start[1], 1]];
    save[start[0]][start[1]] = 0;
    while (stack.length > 0) {
        var _c = stack.pop(), h = _c[0], w = _c[1], c = _c[2];
        for (var i = 0; i < 4; i++) {
            if (h + dh[i] < 0 || h + dh[i] >= mh || w + dw[i] < 0 || w + dw[i] >= mw)
                continue;
            if (map[h + dh[i]][w + dw[i]] == '#')
                continue;
            if (save[h + dh[i]][w + dw[i]] >= c) {
                stack.push([h + dh[i], w + dw[i], c + 1]);
                save[h + dh[i]][w + dw[i]] = c;
            }
        }
    }
    var ans = 0;
    for (var i = 0; i < mh; i++) {
        for (var j = 0; j < mw; j++) {
            if (save[i][j] == 600)
                continue;
            if (ans < save[i][j]) {
                ans = save[i][j];
            }
        }
    }
    to(ans);
};
main();
