import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class D1136 {

	public static void main(String[] args) throws IOException {
//		BufferedReader br = new BufferedReader(new FileReader("F:/books/input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);
		int[] q = new int[n];
		String[] qs = br.readLine().split(" ");
		for(int i=0;i<n;i++) {
			q[i] = Integer.parseInt(qs[i]);
		}
		int nat = q[n-1];
		Map<Integer,List<Integer>> mp = new HashMap<Integer,List<Integer>>();
		List<Integer> natF = new ArrayList<Integer>();
		for(int i=0;i<m;i++) {
			String[] ms = br.readLine().split(" ");
			int u = Integer.parseInt(ms[0]);
			int v = Integer.parseInt(ms[1]);
			insertToMap(mp,u,v);
			if(v == nat) {
				insertToList(natF,u);
			}
		}
		List<Integer> events = new ArrayList<Integer>();
		for(int i=0;i<n-1;i++) {
			if(validEvent(q[i],q[i+1],natF,mp)){
				insertToList(events,i);
			}
		}
		int cnt = 0;
		while(events.size()>0) {
			int i = events.get(0);
			events.remove(0);
			int t = q[i];q[i] = q[i+1];q[i+1] = t;
			if(q[i]==nat) cnt++;
			if(events.size()>0 && events.get(0)==i+1) events.remove(0);
			if(i<(n-2) && validEvent(q[i+1],q[i+2],natF,mp)) {
				events.add(0, i+1);
			}
			if(i>0 && validEvent(q[i-1],q[i],natF,mp)) {
				events.add(0,i-1);
			}
		}
		System.out.println(cnt);
	}

	private static boolean validEvent(int u, int v, 
			List<Integer> natF, Map<Integer, List<Integer>> mp) {
		List<Integer> l = mp.get(u);
		if(l==null) return false;
		int pos = Collections.binarySearch(l, v);
		if(pos<0) return false;
		if(Collections.binarySearch(natF, u)>=0 && 
				Collections.binarySearch(natF, v)<0 )
			return true;
		return false;
	}

	private static void insertToList(List<Integer> l, int v) {
		int pos = Collections.binarySearch(l, v);
		l.add(-pos-1,v);
	}

	private static void insertToMap(Map<Integer, List<Integer>> mp,
			int u, int v) {
		List<Integer> l = mp.get(u);
		if(l==null) {
			l = new ArrayList<Integer>();
			mp.put(u, l);
		}
		insertToList(l,v);
	}

}
