import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int A, B; scanf("%d %d\n", &A, &B);
    int[] a = readln.chomp.split(" ").map!(to!int).array,
          b = readln.chomp.split(" ").map!(to!int).array;
    int f(int index) {
        int x = 0;
        int c = 0;
        foreach (i; index .. B) {
            while (x < A) {
                if (a[x++] == b[i]) {
                    c++;
                    break;
                }
            }
        }
        return c;
    }
    int ans = 0;
    foreach (int i; 0 .. B) {
        //writeln([i, f(i)]);
        ans = max(ans, f(i));
    }
    ans.writeln;
}