#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    h,w=map(int,input().split())
    s=[input() for i in range(h)]
    for i in range(h):
        s[i]=list(s[i])
    for i in range(h):
        for j in range(w):
            if s[i][j]==".":
                s[i][j]=1000
            else:
                s[i][j]=9999
 #   print(s)
    start=[0,0]
    for i in range(h):
        start[1]=s[i].index(min(s[i]))
        if min(s[i]) >= 1111:
            continue
        else:
            start[0]=i
            break
 #   print(start)
    s[start[0]][start[1]]=0

    for kk in range(10000):

        for i in range(h):
            for j in range(w):
                if s[i][j]>1000:
                    continue
                if i+1<h:
                    if s[i][j]>s[i+1][j] and s[i+1][j]<1000:
                            s[i][j]=s[i+1][j]+1
                if i-1>=0:
                    if s[i][j] > s[i - 1][j] and s[i - 1][j] < 1000:
                            s[i][j] = s[i - 1][j] + 1
                if j+1<w:
                    if s[i][j] > s[i][j+1] and s[i][j+1] < 1000:
                            s[i][j] = s[i][j+1] + 1
                if j-1>=0:
                    if s[i][j] > s[i][j - 1] and s[i][j - 1] < 1000:
                            s[i][j] = s[i][j - 1] + 1

 #   print(s)

    temp=[0,0]
    tempm=0
    for i in range(h):
        for j in range(w):
            if s[i][j]>tempm and s[i][j]<9999:
                tempm=s[i][j]
                temp=[i,j]
            if s[i][j]<9999:
                s[i][j]=1000
    start=[temp[0],temp[1]]
    s[start[0]][start[1]]=0

    for kk in range(10000):

        for i in range(h):
            for j in range(w):
                if s[i][j]>1000:
                    continue
                if i+1<h:
                    if s[i][j]>s[i+1][j] and s[i+1][j]<1000:
                            s[i][j]=s[i+1][j]+1
                if i-1>=0:
                    if s[i][j] > s[i - 1][j] and s[i - 1][j] < 1000:
                            s[i][j] = s[i - 1][j] + 1
                if j+1<w:
                    if s[i][j] > s[i][j+1] and s[i][j+1] < 1000:
                            s[i][j] = s[i][j+1] + 1
                if j-1>=0:
                    if s[i][j] > s[i][j - 1] and s[i][j - 1] < 1000:
                            s[i][j] = s[i][j - 1] + 1

#    print(s)
#    for i in range(h):
#        print(s[i])

    temp = [0, 0]
    tempm = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] > tempm and s[i][j] < 9999:
                tempm = s[i][j]
                temp = [i, j]
            if s[i][j] < 9999:
                s[i][j] = 1000

    print(tempm)

if __name__ == "__main__":
    main()