line = gets
A = gets.split
B = gets.split

ans = 0
A.each.with_index do |a, i|
    count = 0
    B.each do |b|
        if A[i] == b
            count += 1
            i += 1
        end
    end
    ans = [ans, count].max
end
puts ans