using System;
class Program{
  static int Height;
  static int Width;
  static void Main(string[] args){
	string[] input1 = Console.ReadLine().Split(' ');
	Height = int.Parse(input1[0]);
	Width = int.Parse(input1[1]);
    int[,] board = new int[Height,Width];
    for (int h = 0; h < Height; h++) {
      char[] input2 = Console.ReadLine().ToCharArray();
      for (int w = 0; w < Width; w++) {
        if (input2[w] == '.') {
          board[h,w] = -1;
        } else {
          board[h,w] = -2;
        }
      }
    }
    int[,] dest3 = new int[board.GetLength(0), board.GetLength(1)];
    Array.Copy(board, dest3, board.Length);
    bool startfound = false;
    int starth = 0;
    int startw = 0;
    while (!startfound) {
      if (board[starth,startw] == -1) {
        startfound = true;
        board[starth,startw] = 0;
      } else {
        if (startw == Width - 1) {
          starth++;
          startw = 0;
        } else {
          startw++;
        }
      }
    }
    
    board = CalcAll(board, starth, startw);
    int max = 0;
    int x = 0;
    int y = 0;
    for (int h = 0; h < Height; h++) {
      for (int w = 0; w < Width; w++) {
          if (board[h,w] > max) {
            max = board[h,w];
            x = h;
            y = w;
          }
        }
      }
    
    dest3[x,y] = 0;
    dest3 = CalcAll(dest3, x, y);
    max = 0;
    x = 0;
    y = 0;
    for (int h = 0; h < Height; h++) {
      for (int w = 0; w < Width; w++) {
          if (board[h,w] > max) {
            max = board[h,w];
            x = h;
            y = w;
          }
        }
      }
    Console.WriteLine(max);
  }
  
  static int[,] CalcAll(int[,] board, int starth, int startw) {
    bool res = false;
    board = CalcAround(board, starth, startw, 1);
    int distNow = 1;
    while (!res) {
      res = true;
      
      for (int h = 0; h < Height; h++) {
        for (int w = 0; w < Width; w++) {
          if (board[h,w] == distNow) {
            board = CalcAround(board, h, w, distNow + 1);
          }
        }
      }
      distNow++;
      
      int zeroNum = 0;
      for (int h = 0; h < Height; h++) {
        for (int w = 0; w < Width; w++) {
          if (board[h,w] == -1) {
            zeroNum++;
          }
        }
      }
      if (zeroNum > 0) {
        res = false;
      }
    }
    return board;
  }
  
  static int[,] CalcAround(int[,] board, int h, int w, int dist) {
    if (h > 0) {
        if (board[h - 1, w] == -1 || board[h - 1, w] > dist) {
          board[h - 1, w] = dist;
        }
      }
      if (h < Height - 1) {
        if (board[h + 1, w] == -1 || board[h + 1, w] > dist) {
          board[h + 1, w] = dist;
        }
      }
      if (w > 0) {
        if (board[h, w - 1] == -1 || board[h, w - 1] > dist) {
          board[h, w - 1] = dist;
        }
      }
      if (w < Width - 1) {
        if (board[h, w + 1] == -1 || board[h, w + 1] > dist) {
          board[h, w + 1] = dist;
        }
      }
    return board;
  }
}