#include <bits/stdc++.h>
using namespace std;
int ara[300005], dp[300005];
int main() {
  int n, c, q, a, b, mn = 1000000;
  long long int ans = 0;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &c);
    ara[c] = i;
    dp[i] = n + 1;
  }
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &a, &b);
    if (ara[a] > ara[b])
      dp[ara[b]] = min(dp[ara[b]], ara[a]);
    else
      dp[ara[a]] = min(dp[ara[a]], ara[b]);
  }
  for (int i = n; i >= 1; i--) {
    mn = min(dp[i], mn);
    ans += mn - i;
  }
  cout << ans;
}
