#include <bits/stdc++.h>
using namespace std;
long long int v[300005], result[300005];
long long int n, m;
int main() {
  long long int n, m;
  scanf("%lld%lld", &n, &m);
  for (long long int i = 1; i <= n; i++) {
    long long int a;
    scanf("%lld", &a);
    v[a] = i;
  }
  for (long long int i = 1; i <= m; i++) {
    long long int l, r;
    scanf("%lld%lld", &l, &r);
    l = v[l];
    r = v[r];
    if (l > r) swap(l, r);
    result[r] = max(result[r], l + 1);
  }
  long long int x = 1, ans = 0;
  for (long long int i = 1; i <= n; i++) {
    x = max(x, result[i]);
    ans += i - x + 1;
  }
  cout << ans << endl;
}
