def bfs(x, y)
  res = 0
  d = Array.new(H).map{Array.new(W, INF)}
  d[x][y] = 0
  que = [[x, y, nil]]
  until que.empty?
    nx, ny, direction = que.shift
    d[nx][ny] = 0
    res += 1
    if direction.nil?
      que << [nx-1, ny, 'vertical'] if nx > 0 && G[nx-1][ny] == '.' && d[nx-1][ny] == INF
      que << [nx+1, ny, 'vertical'] if nx < H-1 && G[nx+1][ny] == '.' && d[nx+1][ny] == INF
      que << [nx, ny-1, 'horizontal'] if ny > 0 && G[nx][ny-1] == '.' && d[nx][ny-1] == INF
      que << [nx, ny+1, 'horizontal'] if ny < W-1 && G[nx][ny+1] == '.' && d[nx][ny+1] == INF
    elsif direction == 'vertical'
      que << [nx-1, ny, 'vertical'] if nx > 0 && G[nx-1][ny] == '.' && d[nx-1][ny] == INF
      que << [nx+1, ny, 'vertical'] if nx < H-1 && G[nx+1][ny] == '.' && d[nx+1][ny] == INF
    else
      que << [nx, ny-1, 'horizontal'] if ny > 0 && G[nx][ny-1] == '.' && d[nx][ny-1] == INF
      que << [nx, ny+1, 'horizontal'] if ny < W-1 && G[nx][ny+1] == '.' && d[nx][ny+1] == INF
    end
  end
  res
end

INF = '*'#10**9
H, W = gets.chomp.split.map(&:to_i)
G = []
H.times { G << gets.chomp }
ans = 0
H.times do |i|
  W.times do |j|
    next if G[i][j] == '#'

    ans = [ans, bfs(i, j)].max
  end
end
puts ans