import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class cf {
	public static void main(String[] args) {
		FS scan = new FS(System.in);
		int N = scan.nextInt(), M = scan.nextInt();
		DisjointSet d = new DisjointSet(N);
		int[] list = new int[N];
		for(int i=0;i<N;i++)list[i] = scan.nextInt()-1;
		boolean[] jump = new boolean[N];
		for(int i=0;i<M;i++){
			int u = scan.nextInt()-1, v = scan.nextInt()-1;
			if(u==list[N-1])
				jump[v]=true;
			if(v==list[N-1])
				jump[u]=true;
			if(!d.find(u, v))
				d.union(u, v);
		}
		
		int sol = 0;
		for(int i=N-2;i>=0;i--){
			if(!d.find(list[N-1], list[i]))break;
			if(jump[list[i]])sol++;
		}
		System.out.println(sol);
	}
	
	private static class DisjointSet {
		int[] id, sz;
		public DisjointSet(int N) {//N=Number of verts
			id = new int[N];
			sz = new int[N];
			for (int i=0;i<N;i++){sz[i]=1;id[i]=i;}
		}
		 
		private int root(int i){
			return id[i] = (i!=id[i])?root(id[i]):i;
		}
		public boolean find(int p, int q){
			return root(p)==root(q);
		}
		public void union(int p, int q){
			int i=root(p);
			int j=root(q);
			if (sz[i]<sz[j]){id[i]=j;sz[j]+=sz[i];}
			else 			{id[j]=i;sz[i]+=sz[j];};
		}
	}
	private static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() { return Double.parseDouble(next());}
	}
}
