# -*- coding: utf-8 -*-
"""
Created on Sun Jan 12 21:32:04 2020

@author: maezawa
"""
import copy

h, w = list(map(int, input().split()))
board = [[] for _ in range(h+2)]

for i in range(1,h+1):
    s = input()
    board[i] = list('*'+s+'*')
board[0] = list('*'*(w+2))
board[h+1] = list('*'*(w+2))
last =  copy.deepcopy(board)   
#print(board)

def search(y,x,n):
    if board[y][x] == '*':
        return
    dirs = [[-1,0],[0,1],[1,0],[0,-1]]
    nextcells = []
    forwcells=[[y,x]]
    while forwcells:
        islast = True
        curcell = forwcells.pop()
        for di in dirs:
            nextcells.append([curcell[0]+di[0],curcell[0]+di[1]])
        n += 1
        for ncel in nextcells:
            if board[ncel[0]][ncel[1]] == '.':
                board[ncel[0]][ncel[1]] = n
                forwcells.append((ncel))
                islast = False
        if islast:
            last[curcell[0]][curcell[1]] = "@"                       
    
for i in range(1,h+1):
    for j in range(1,w+1):
        if board[i][j] == '.':
            board[i][j] = 0
            search(i,j,0)

candidates = [0]            
for i in range(1,h+1):
    for j in range(1,w+1):
        if last[i][j] == '@':
            candidates.append(board[i][j])
            
candidates.sort(reverse=True)
ans = candidates[0]+candidates[1]
print(ans)
