#include <stdio.h>
#include <stdbool.h>
#define MAX_SIZE 500001
int read() {
char c = getchar();
int x = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
bool iscut[MAX_SIZE];
typedef struct {
int value;
bool is_exist;
} HashTable;
int main() {
int n, m, i;
n = read();
m = read();
int a[MAX_SIZE];
for (i = 1; i <= n; i++) {
a[i] = read();
}
int b[MAX_SIZE];
for (i = 1; i <= m; i++) {
b[i] = read();
}
HashTable hash_table[MAX_SIZE] = {0};
for (i = 1; i <= m; i++) {
hash_table[b[i]].is_exist = true;
}
int cnt = 0;
iscut[0] = true;
for (i = 1; i <= n; i++) {
if (hash_table[a[i]].is_exist) {
iscut[i] = true;
}
if (iscut[i-1] && !iscut[i]) {
cnt++;
}
}
printf("%d", cnt);
return 0;
}