#include <bits/stdc++.h>   using namespace std;   int num[500005];   int maps[500005];   int to[500005];   int main() {     ios::sync_with_stdio(0);     int n, m;     int l, r;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       to[num[i]] = i;     }     for (int i = 1; i <= m; i++) {       scanf( %d%d , &l, &r);       if (to[r] < to[l]) {         int tmp = r;         r = l;         l = tmp;       }       maps[to[r]] = max(to[l], maps[to[r]]);     }     l = 1;     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (maps[i] >= l) l = maps[i] + 1;       ans += i - l + 1;     }     cout << ans << endl;   }   