import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def neighbors4(x, y):
  dxy = (0, 1, 0, -1, 0 )
  for i in range(4):
    yield(x + dxy[i], y + dxy[i+1])

h,w = get_nums_l()

grid_s = [ input() for _ in range(h) ]
grid = [ [-1] * (w+2) for _ in range(h+2) ]

log(grid_s)

for y in range(1,h+1):
    for x in range(1, w+1):
        if grid_s[y-1][x-1] == ".":
            grid[y][x] = 999999999999999999

start_x = 1
start_y = 1
while grid[start_y][start_x] == -1:
    start_x += 1
    if start_x > w:
        start_x = 1
        start_y += 1

grid[start_y][start_x] = 0

que = deque()
que.append((start_x, start_y, 1))

while que:
    x,y,score = que.popleft()

    for nx,ny in neighbors4(x,y):
        if grid[ny][nx] != -1 and grid[ny][nx] > score:
            grid[ny][nx] = score
            que.append((nx, ny, score+1))

max_ = 0
max_x = -1
max_y = -1

for y in range(1,h+1):
    for x in range(1, w+1):
        if grid[y][x] > max_:
            max_ = grid[y][x]
            max_x = x
            max_y = y

for y in range(1,h+1):
    for x in range(1, w+1):
        if grid_s[y-1][x-1] == ".":
            grid[y][x] = 999999999999999999

que = deque()
que.append((max_x, max_y, 1))


grid[max_y][max_x] = 0

while que:
    x,y,score = que.popleft()

    for nx,ny in neighbors4(x,y):
        if grid[ny][nx] != -1 and grid[ny][nx] > score:
            grid[ny][nx] = score
            que.append((nx, ny, score+1))

max_ = 0
max_x = -1
max_y = -1

for y in range(1,h+1):
    for x in range(1, w+1):
        if grid[y][x] > max_:
            max_ = grid[y][x]
            max_x = x
            max_y = y

for g in grid:
    log(g)

print(max_)