#include <bits/stdc++.h>
using namespace std;
long long int a[500001], pos[500001], open[500001], dp[500001];
int main() {
  ios::sync_with_stdio(false);
  ;
  long long int i, j, x, y, ans = 0, n, q, z;
  cin >> n >> q;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (i = 1; i <= n; i++) open[i] = 0;
  for (i = 1; i <= q; i++) {
    cin >> x >> y;
    x = pos[x];
    y = pos[y];
    if (x > y) swap(x, y);
    open[y] = max(open[y], x);
  }
  dp[1] = 0;
  for (i = 2; i <= n; i++) {
    x = open[i];
    y = dp[i - 1];
    z = max(x, y);
    dp[i] = z;
    ans += i - z;
  }
  cout << ans + 1;
  return 0;
}
