#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr static int mod = 1e9 + 7;
constexpr static int inf = (1 << 30) - 1;
constexpr static Int infll = (1LL << 61) - 1;
int Competitive_Programming =
    (ios_base::sync_with_stdio(false), cin.tie(nullptr),
     cout << fixed << setprecision(15), 0);
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> p(N), inv(N + 1, -1);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    inv[p[i]] = i;
  }
  vector<vector<int>> edge(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    edge[max(inv[a], inv[b])].emplace_back(min(inv[a], inv[b]));
  }
  Int ans = 0;
  vector<bool> used(N + 1, false);
  for (int left = 0, right = 0; left < N; left++) {
    while (right < N) {
      used[right] = true;
      bool ng = false;
      for (int i = edge[right].size() - 1; i >= 0; i--) {
        if (used[edge[right][i]]) {
          ng = true;
          break;
        }
        edge[right].pop_back();
      }
      if (ng) {
        used[p[right]] = false;
        break;
      }
      right++;
    }
    ans += right - left;
    used[left] = false;
  }
  cout << ans << "\n";
}
