using System;
using System.Linq;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static string Alp = "abcdefghijklmnopqrstuvwxyz";
    static int h,w;
    static string[] map;
    static int[] dirX = {1,0,-1,0};
    static int[] dirY = {0,1,0,-1};
    static void Main()
    {
      var input = ScanIntArray();
      h = input[0];
      w = input[1];
      map = new string[h];
      
      int maxStep = -1;
      for(int i=0; i<h; i++) map[i] = ScanStr();
      int startX, startY, goalX = h, goalY = w;
      for (int i = 0; i < h; i++) {
        for (int k = 0; k < w; k++) {
          if(map[i][k] == '#') continue;
          maxStep = Math.Max(maxStep, GetMaxPath(i,k));
        }
      }
      
      
      WriteLine($"{maxStep}");
    }
    
    static int GetMaxPath(int startX, int startY)
    {
      int[][] dist = Enumerable.Repeat(0, h).Select(_=>Enumerable.Repeat(-1,w).ToArray()).ToArray(); 
      dist[startX][startY] = 0;
      Queue<int[]> que = new Queue<int[]>();
      que.Enqueue(new int[]{startX, startY});
        
      while (que.Count != 0) {
        var curPos = que.Dequeue();
        int x = curPos[0];
        int y = curPos[1];

        for (int dir = 0; dir < 4; dir++) {
          int nextX = x + dirX[dir];
          int nextY = y + dirY[dir];
          if (nextX < 0 || nextX >= h || nextY < 0 || nextY >= w) continue;
          if (map[nextX][nextY] == '#') continue;

          if (dist[nextX][nextY] == -1 || dist[nextX][nextY] > dist[x][y]+1) {
            que.Enqueue(new int[]{nextX, nextY});
            dist[nextX][nextY] = dist[x][y] + 1;
          }
        }
      }
      
      return dist.Max(_=>_.Max());
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
  }
  
  static class MyMath {
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 17872