#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
int a[SIZE], p[SIZE];
int dp[SIZE];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (1); i < (n + 1); ++i) {
    scanf("%d", &(a[i]));
    p[a[i]] = i;
  }
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = p[x];
    y = p[y];
    if (x > y) swap(x, y);
    dp[y] = max(dp[y], x);
  }
  long long an = 0;
  int ma = 0;
  for (int i = (1); i < (n + 1); ++i) {
    ma = max(dp[i], ma);
    an += i - ma;
  }
  cout << an;
  return 0;
}
