#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    int x, count = 0;
    int a[n];
    int b[2][m];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> b[0][i] >> b[1][i];
      if (b[1][i] == a[n - 1]) count++;
    }
    cout << count << endl;
  }
}
