### BUGGY CODE ###

from array import array

h, w = map(int, input().split())
maze = []
for i in range(h):
    maze.append(input())

g = []

for i in range(w * h):
    g.append(array('l', [10000000] * (w * h)))

for i in range(w * h):
    g[i][i] = 0

for i in range(h):
    for j in range(w):
        if maze[i][j] == '#':
            continue
        if maze[i][j] == '.':
            if i > 0 and maze[i-1][j] != '#':
                g[i * w + j][(i-1) * w + j] = 1
                g[(i-1) * w + j][i * w + j] = 1
            if i < h-1 and maze[i+1][j] != '#':
                g[i * w + j][(i+1) * w + j] = 1
                g[(i+1) * w + j][i * w + j] = 1
            if j > 0 and maze[i][j-1] != '#':
                g[i * w + j][i * w + j-1] = 1
                g[i * w + j-1][i * w + j] = 1
            if j < w-1 and maze[i][j+1] != '#':
                g[i * w + j][i * w + j+1] = 1
                g[i * w + j+1][i * w + j] = 1

def floyed(g, h, w):
    for k in range(h*w):
        for i in range(h*w):
            for j in range(h*w):
                if i == j or i == k or k == j:
                    continue
                if g[i][j] > g[i][k] + g[k][j]:
                    g[i][j] = g[i][k] + g[k][j]

floyed(g,h,w)
result = 0

for i in range(w*h):
    for j in range(w*h):
        if g[i][j] < 10000000:
            if g[i][j] > result:
                result = g[i][j]

print(result)


### FIXED CODE ###

from array import array

h, w = map(int, input().split())
maze = []
for i in range(h):
    maze.append(input())

cnt = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == '.':
            cnt += 1

if cnt == w*h:
    print(w+h-2)
else:
    nodes = h*w

    g = []

    for i in range(nodes):
        g.append(array('l', [10000000] * (w * h)))

    for i in range(nodes):
        g[i][i] = 0

    for i in range(h):
        for j in range(w):
            if maze[i][j] == '#':
                continue
            if maze[i][j] == '.':
                if i > 0 and maze[i-1][j] != '#':
                    g[i * w + j][(i-1) * w + j] = 1
                    g[(i-1) * w + j][i * w + j] = 1
                if i < h-1 and maze[i+1][j] != '#':
                    g[i * w + j][(i+1) * w + j] = 1
                    g[(i+1) * w + j][i * w + j] = 1
                if j > 0 and maze[i][j-1] != '#':
                    g[i * w + j][i * w + j-1] = 1
                    g[i * w + j-1][i * w + j] = 1
                if j < w-1 and maze[i][j+1] != '#':
                    g[i * w + j][i * w + j+1] = 1
                    g[i * w + j+1][i * w + j] = 1

    def floyed(g, nodes):
        result = 0
        for k in range(nodes):
            for i in range(nodes):
                if i == k:
                    continue
                if g[i][k] == 10000000:
                    continue
                for j in range(nodes):
                    if g[k][j] == 10000000:
                        continue
                    if i == j or i == k or k == j:
                        continue
                    if g[i][j] > g[i][k] + g[k][j]:
                        g[i][j] = g[i][k] + g[k][j]

    floyed(g,nodes)

    result = 0
    for i in range(nodes):
        for j in range(nodes):
            if g[i][j] < 10000000 and g[i][j] > result:
                result = g[i][j]
    print(result)