n, m = map(int, input().strip().split())
p = list(map(int, input().strip().split()))
pairs = {}
for _ in range(m):
    u, v = map(int, input().strip().split())
    pairs[u * 1000000 + v] = True

def exchange(idx):
    if idx == 0:
        return False
    global p
    u, v = p[idx - 1], p[idx]
    if u * 1000000 + v in pairs:
        p[idx], p[idx - 1] = p[idx - 1], p[idx]
        return True
    elif exchange(idx - 1):
            u, v = p[idx - 1], p[idx]
            if u * 1000000 + v in pairs:
                p[idx], p[idx - 1] = p[idx - 1], p[idx]
                return True
    return False

idx = n - 1
while exchange(idx):
    idx -= 1
print(n - idx - 1)