#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, input;
long long counter = 0;
cin >> n >> m;
unordered_map<int, int> freq;
for (int i = 0; i < n; i++)
{
cin >> input;
freq[input]++;
}
for (int i = 0; i < m; i++)
{
cin >> input;
counter += freq[input];
}
cout << counter;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgIGludCBuLCBtLCBpbnB1dDsKICAgIGxvbmcgbG9uZyBjb3VudGVyID0gMDsKICAgIAogICAgY2luID4+IG4gPj4gbTsKCiAgICB1bm9yZGVyZWRfbWFwPGludCwgaW50PiBmcmVxOwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgewogICAgICAgIGNpbiA+PiBpbnB1dDsKICAgICAgICBmcmVxW2lucHV0XSsrOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbTsgaSsrKQogICAgewogICAgICAgIGNpbiA+PiBpbnB1dDsKICAgICAgICBjb3VudGVyICs9IGZyZXFbaW5wdXRdOwogICAgfQoKICAgIGNvdXQgPDwgY291bnRlcjsKfQ==