line = gets.split
if line.size == 1
    line = gets
end
A = gets.split
B = gets.split

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