#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[327680];
int ind[327680];
pair<int, int> p[327680];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    ind[a[i]] = i;
  }
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x = ind[x];
    y = ind[y];
    if (x > y) swap(x, y);
    p[i] = make_pair(x, y);
  }
  sort(p + 1, p + 1 + m);
  long long right = n + 1, ans = 0;
  int now = m;
  for (int i = n; i >= 1; --i) {
    while (m > 0 && p[now].first == i)
      right = min(right, (long long)p[now--].second);
    ans += right - i;
  }
  cout << ans << endl;
  return 0;
}
