m, n = gets.split.map &:to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
max = 0
(0..n-1).each{|j|
    c = 0   
    (0..m-1).each{|i|
        if a[i] == b[j]
            j += 1 
            c += 1
        end
    }
    max = c if c > max
}   
p max