You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}). 

Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn't count intervals (x, y) that contain at least one foe pair in it (the positions and order of the values from the foe pair are not important).

Consider some example: p = [1, 3, 2, 4] and foe pairs are {(3, 2), (4, 2)}. The interval (1, 3) is incorrect because it contains a foe pair (3, 2). The interval (1, 4) is also incorrect because it contains two foe pairs (3, 2) and (4, 2). But the interval (1, 2) is correct because it doesn't contain any foe pair.


-----Input-----

The first line contains two integers n and m (1 ≤ n, m ≤ 3·10^5) — the length of the permutation p and the number of foe pairs.

The second line contains n distinct integers p_{i} (1 ≤ p_{i} ≤ n) — the elements of the permutation p.

Each of the next m lines contains two integers (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the i-th foe pair. Note a foe pair can appear multiple times in the given list.


-----Output-----

Print the only integer c — the number of different intervals (x, y) that does not contain any foe pairs.

Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.


-----Examples-----
Input
4 2
1 3 2 4
3 2
2 4

Output
5

Input
9 5
9 7 2 3 1 4 6 5 8
1 6
4 5
2 7
7 2
2 7

Output
20



-----Note-----

In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).

Difficulty: interview

Starter code:

Solutions:
def main():
    from sys import stdin
    n, m = list(map(int, input().split()))
    n += 1
    aa, pos, duo = [0] * n, [0] * n, [0] * n
    for i, a in enumerate(map(int, input().split()), 1):
        aa[i] = a
        pos[a] = i
    for s in stdin.read().splitlines():
        x, y = list(map(int, s.split()))
        px, py = pos[x], pos[y]
        if px > py:
            if duo[x] < py:
                duo[x] = py
        else:
            if duo[y] < px:
                duo[y] = px
    res = mx = 0
    for i, a in enumerate(aa):
        if mx < duo[a]:
            mx = duo[a]
        res += i - mx
    print(res)


def __starting_point():
    main()

__starting_point()

"""
652C - Враждебные пары
http://codeforces.com/problemset/problem/652/C
Предподсчитаем сначала для каждого числа x его позицию posx в перестановке. Это легко сделать за линейное время. Теперь рассмотрим некоторую враждебную пару (a, b) (можно считать, что posa < posb). Запомним для каждого числа a самую левую позицию posb такую, что (a, b) образуют враждебную пару. Обозначим эту величину za. Теперь будем идти по перестановке справа налево и поддерживать позицию rg наибольшего корректного интервала с левым концом в текущей позиции перестановки lf. Значение rg пересчитывается следующим образом: rg = min(rg, z[lf]). Соответсвенно к ответу на каждой итерации нужно прибавлять величину rg - lf + 1.
"""


def main():
    from sys import stdin
    n, m = list(map(int, input().split()))
    n += 1
    aa, pos, duo = [0] * n, [0] * n, [0] * n
    for i, a in enumerate(map(int, input().split()), 1):
        aa[i] = a
        pos[a] = i
    for s in stdin.read().splitlines():
        x, y = list(map(int, s.split()))
        px, py = pos[x], pos[y]
        if px > py:
            if duo[x] < py:
                duo[x] = py
        else:
            if duo[y] < px:
                duo[y] = px
    res = mx = 0
    for i, a in enumerate(aa):
        if mx < duo[a]:
            mx = duo[a]
        res += i - mx
    print(res)


def __starting_point():
    main()

__starting_point()

def f():
    sizes = input().split(' ')
    n, m = int(sizes[0]), int(sizes[1]) 
    permStr = input().split(' ')
    pairsStr = [input() for i in range(m)]

    indexes = [0 for i in range(n+1)]
    for i in range(n):
        indexes[int(permStr[i])] = i+1
    lowerNums = [0 for i in range(n+1)]

    for i in range(m):
        pair = pairsStr[i].split(" ")
        a, b = indexes[int(pair[0])], indexes[int(pair[1])]
        if a < b:
            l = a
            h = b
        else:
            l = b
            h = a
        if l > lowerNums[h]:
            lowerNums[h] = l

    counter = 0
    left = 0
    for i in range(1,n+1):
        candidate = lowerNums[i]
        if candidate > left:
            r=i-1-left
            q=i-1-candidate
            counter += (r*(r-1) - q*(q-1))//2
            left = candidate
    r=i-left
    counter += r*(r-1)//2

    print(counter + n)


f() 


def main():
    from sys import stdin
    n, m = list(map(int, input().split()))
    n += 1
    aa, pos, duo = [0] * n, [0] * n, [0] * n
    for i, a in enumerate(map(int, input().split()), 1):
        aa[i] = a
        pos[a] = i
    for s in stdin.read().splitlines():
        x, y = list(map(int, s.split()))
        px, py = pos[x], pos[y]
        if px > py:
            if duo[x] < py:
                duo[x] = py
        else:
            if duo[y] < px:
                duo[y] = px
    res = mx = 0
    for i, a in enumerate(aa):
        if mx < duo[a]:
            mx = duo[a]
        res += i - mx
    print(res)


def __starting_point():
    main()




# Made By Mostafa_Khaled

__starting_point()

#!/usr/bin/env python3
 


import sys

def solver():
    import re
    lines = iter(sys.stdin.read().split('\n'))
    n, m = tuple(map(int, next(lines).split(' ')))
    revp = [0, ] * (n+1)
    for i, val in enumerate(map(int, next(lines).split(' '))):
        revp[val] = i
    pairs = [-1] * (n+1)
    pairs[-1] = n-1
    for i in range(m):
        a, b = tuple(map(int, next(lines).split(' ')))
        a, b = revp[a], revp[b]
        if b > a:
            a, b = b, a
        pairs[a] = max(pairs[a], b)
    res = 0
    pos = 0
    for right, left in enumerate(pairs):
        if left == -1:
            continue
        for i in range(pos, left+1):
            res = res + right - i
        pos = max(pos, left + 1)
    return res
        
def main():
    res = solver()
    sys.stdout.write("{}\n".format(res))
    return 0
 
def __starting_point():
    main()

__starting_point()

#!/usr/bin/env python3
 

 
def solver():
    import sys
    it = (int(x) for line in sys.stdin.read().splitlines() for x in line.split(' '))
    n, m = next(it), next(it)
    revp = [0, ] * (n+1)
    for i in range(n):
        revp[next(it)] = i
    pairs = [-1] * (n+1)
    pairs[-1] = n-1
    for _ in range(m):
        a, b = next(it), next(it)
        a, b = revp[a], revp[b]
        if b > a:
            a, b = b, a
        pairs[a] = max(pairs[a], b)
    res = 0
    pos = 0
    for right, left in enumerate(pairs):
        if left == -1:
            continue
        for i in range(pos, left+1):
            res = res + right - i
        pos = max(pos, left + 1)
    return res
        
def main():
    import sys
    res = solver()
    sys.stdout.write("{}\n".format(res))
    return 0
 
def __starting_point():
    main()

__starting_point()

from sys import stdin


def main():
    n, k = list(map(int, stdin.readline().split()))
    ar = list(map(int, stdin.readline().split()))
    lk = {ar[i] - 1: i for i in range(n)}
    pair = [-1 for _ in range(n)]
    for _ in range(k):
        x, y = list(map(int, stdin.readline().split()))
        if lk[y - 1] > lk[x - 1]:
            pair[y - 1] = max(pair[y - 1], lk[x - 1])
        else:
            pair[x - 1] = max(pair[x - 1], lk[y - 1])
    start = 0
    end = 0
    ok = True
    ans = 0
    while end < n:
        while end < n and ok:
            curr = ar[end] - 1
            if start <= pair[curr]:
                ok = False
            else:
                end += 1
        if end < n:
            while start <= pair[ar[end] - 1]:
                ans += end - start
                start += 1
        else:
            ans += (end - start + 1) * (end - start) // 2
        ok = True
    print(ans)


def __starting_point():
    main()

__starting_point()