using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static int h;
    static int w;
    static char[][] ss;

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        h     = int.Parse(spl[0]);
        w     = int.Parse(spl[1]);

        ss = new char[h][];
        for(int i=0; i<h; i++) {
            ss[i] = new char[w];
            var s = input.ReadLine();
            for(int j=0; j<w; j++) {
                ss[i][j] = s[j];
            }
        }

        int max = 0;
        for(int sh=0; sh<h; sh++) {
            for(int sw=0; sw<w; sw++) {
                for(int eh=0; eh<h; eh++) {
                    for(int ew=0; ew<w; ew++) {
                        if(ss[sh][sw] == '.' && ss[eh][ew] == '.') {
                            max = Math.Max(calc(sh, sw, eh, ew), max);
                        }
                    }
                }
            }
        }

        return max;
    }

    static int calc(int sh, int sw, int gh, int gw) {
        var tbl = new int[h][];
        for (int ii = 0; ii < h; ii++) {
            tbl[ii] = new int[w];
            for(int jj = 0; jj < w; jj++) {
                tbl[ii][jj] = int.MaxValue;
            }
        }

        sett(sh, sw, 0, tbl);
        return tbl[gh][gw];
    }

    static void sett(int i, int j, int value, int[][] tbl) {
        if (i < 0 || i >= h || j < 0 || j >= w) return;
        if (ss[i][j] == '#') return;

        if(value < tbl[i][j]) {
            tbl[i][j] = value;
            sett(i - 1, j, value + 1, tbl);
            sett(i + 1, j, value + 1, tbl);
            sett(i, j - 1, value + 1, tbl);
            sett(i, j + 1, value + 1, tbl);
        }
    }
}
