#include <bits/stdc++.h>
using namespace std;
const int MAX_VAL = 1e6 + 5; 
const int MAX_N = 1e7 + 5;   
int a[MAX_VAL];
int main() {
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
freopen("CAPSO.inp", "r", stdin);
    freopen("CAPSO.out", "w", stdout);

    int N, M;
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) {
        int x;
        cin >> x;
        a[x]++;
    }

    long long result = 0; 
    for (int j = 1; j <= M; ++j) {
        int x;
        cin >> x;
        result += a[x]; 
    }

    cout << result << "\n";
    return 0;
}