#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    h, w = LI()
    s = SR(h)
    q = deque()
    for i in range(h):
        for j in range(w):
            if s[i][j]==".":
                q.append((i, j))
                break
    dist = defaultdict(int)
    dist[q[0]] = 1
    while q:
        p = q.popleft()
        dp = dist[p]
        for mx, my in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            my += p[0]
            mx += p[1]
            if 0 <= mx < w and 0 <= my < h:
                if dist[(my, mx)] or s[my][mx] == "#":
                    continue
                dist[(my, mx)] = dp + 1
                q.append((my,mx))
    dist = list(dist.items())
    dist.sort(key=lambda x: x[1], reverse=True)
    q = deque()
    q.append(dist[0][0])
    dist = defaultdict(int)
    dist[q[0]] = 1
    while q:
        p = q.popleft()
        dp = dist[p]
        for mx, my in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
            my += p[0]
            mx += p[1]
            if 0 <= mx < w and 0 <= my < h:
                if dist[(my, mx)] or s[my][mx] == "#":
                    continue
                dist[(my, mx)] = dp + 1
                q.append((my,mx))
    print(max(dist.values())-1)
    return


#main
if __name__ == '__main__':
    solve()
