using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC151D {
    class Program {
        static void Main(string[] args) {
            var mazeSize = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var cells = new List<Cell>();
            var maxDist = 0;
            for (var i = 0; i < mazeSize[0]; i++) {
                var l = Console.ReadLine();
                for (var j = 0; j < l.Length; j++) {
                    if (l[j] == '.') cells.Add(new Cell(j, i));
                }
            }

            cells.ForEach(c => c.FindNeighbors(cells));

            for (var i = 0; i < cells.Count; i++) {
                for (var j = 0; j < cells.Count - i; j++) {
                    if (i == j) continue;
                    var start = cells[i];
                    var goal = cells[j];
                    var searching = start.neighbors;
                    var dist = 1;
                    while (true) {
                        searching.ForEach(c => c.passed = true);
                        if (goal.passed) {
                            maxDist = Math.Max(maxDist, dist);
                            break;
                        }

                        searching = searching.Select(c => c.neighbors)
                            .Aggregate(new List<Cell>(), (list, l) => {
                                list.AddRange(l);
                                return list;
                            })
                            .Distinct()
                            .Where(c => !c.passed)
                            .ToList();
                        dist++;
                    }

                    cells.ForEach(c => c.passed = false);
                }
            }

            Console.WriteLine(maxDist);
        }

        public class Cell {
            public readonly int x;
            public readonly int y;
            public bool passed;

            public readonly List<Cell> neighbors = new List<Cell>();

            public Cell(int x, int y) {
                this.x = x;
                this.y = y;
            }

            public void FindNeighbors(List<Cell> cells) {
                neighbors.AddRange(cells.Where(c => Cond(Math.Abs(c.x - x), Math.Abs(c.y - y))));
            }

            private static bool Cond(int lhs, int rhs) => (lhs == 0 && rhs == 1) || (lhs == 1 && rhs == 0);
        }
    }
}