H, W = map(int, input().split())
mss=[]
for i in range(H):
    mss.append([])
    for j in input():
        mss[i].append(j)
movable_list = []
for h in range(H):
    movable_list.append([])
    for w in range(W):
        movable_list[h].append([])
        if mss[h][w] != "#":
            if h-1 >= 0:
                if mss[h-1][w] != "#":
                    movable_list[h][w].append([h-1,w])
            if h+1 <=H-1:
                if mss[h+1][w] != "#":
                    movable_list[h][w].append([h+1, w])
            if w-1 >=0:
                if mss[h][w-1] != "#":
                    movable_list[h][w].append([h, w-1])
            if w+1 <= W-1:
                if mss[h][w+1] != "#":
                    movable_list[h][w].append([h, w+1])

max_list = [0]*(H*W)
for h in range(H):
    for w in range(W):
        canmove = movable_list[h][w]    
        pass_list = []
        if mss[h][w] != "#":
            pass_list.append([h,w])
            judge = True
            while judge:
                judge = False
                temp=[]
                for i in canmove:
                    if i not in pass_list: 
                        judge = True
                        pass_list.append(i)
                        temp.extend(movable_list[i[0]][i[1]])
                if judge:
                    max_list[h*W+w] += 1
                canmove = temp
                        
print(max(max_list))
