#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 3e5 + 10;
unordered_set<long long> cur;
set<long long> foe[MAXN];
long long arr[MAXN], pos[MAXN];
long long n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    pos[arr[i]] = i;
  }
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    foe[a].insert(b);
    foe[b].insert(a);
  }
  long long top = 0, ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long u : foe[arr[i]]) {
      if (pos[u] < i) top = max(top, pos[u] + 1);
    }
    ans += i - top + 1;
  }
  cout << ans << endl;
  return 0;
}
