#include <bits/stdc++.h>
const int MAX_N = 3 * 100000;
using namespace std;
class CTree {
 private:
  int tab[(1 << 21) + 7];
  int lElem;
  int lLisci;

 public:
  void init(int _lElem) {
    lElem = _lElem;
    for (lLisci = 1; lLisci < lElem; lLisci <<= 1)
      ;
  }
  void insert(int _p, int _val) {
    int i = lLisci + _p - 1;
    tab[i] += _val;
    i /= 2;
    while (i >= 1) {
      tab[i] = tab[2 * i] + tab[2 * i + 1];
      i /= 2;
    }
  }
  int query() {
    int i = 1;
    if (tab[1] == 0)
      return lElem + 1;
    else {
      while (i < lLisci) {
        if (tab[2 * i] != 0)
          i = 2 * i;
        else
          i = 2 * i + 1;
      }
    }
    return i - lLisci + 1;
  }
} tree;
int n, m;
int p[MAX_N + 7];
int pos[MAX_N + 7];
int ogr[MAX_N + 7];
long long result;
int main() {
  scanf("%d%d", &n, &m);
  tree.init(n + 2);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p[i]);
    pos[p[i]] = i;
    ogr[p[i]] = n + 1;
  }
  for (int i = 1, a, b; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    if (pos[a] > pos[b]) swap(a, b);
    ogr[a] = min(ogr[a], pos[b]);
  }
  int beg = 1, end = 1;
  for (; beg <= n; ++beg) {
    for (; end <= n; ++end) {
      if (end >= tree.query()) break;
      tree.insert(ogr[p[end]], 1);
    }
    result += end - beg;
    tree.insert(ogr[p[beg]], -1);
  }
  printf("%I64d\n", result);
  return 0;
}
