def dfs(a,k):
     used[a] = 1
     s = k
     for elem in gr[a]:
          if used[elem] == -1:
               s = min(k,dfs(elem,min(k,d.index(elem+1))))
     return s
n,m = map(int, input(). split())
d = list(map(int, input(). split()))
gr = [[] for i in range(n)]
for i in range(m):
     a,b = map(int, input(). split())
     gr[a-1].append(b-1)
     gr[b-1].append(a-1)
used = [-1]*n
print(n-1-dfs(d[n-1]-1,n-1))