import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class NastyaLunch {

	public static int n, m;
	public static int[] array;
	public static Map<Integer, Integer> personToPosition = new HashMap<>();
	public static int[][] pairs;
	public static Map<Pair, Integer> pairToIndex = new HashMap<>();
	
	public static int nastya;
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer tok = new StringTokenizer(br.readLine());
		n = Integer.parseInt(tok.nextToken());
		m = Integer.parseInt(tok.nextToken());
		
		array = new int[n];
		
		tok = new StringTokenizer(br.readLine());
		for(int i = 0; i < n; i++) {
			int num = Integer.parseInt(tok.nextToken());;
			array[i] = num;
			personToPosition.put(/*array[i]*/num, i);
			if(i == n - 1) {
				nastya = num;
			}
		}
		
		pairs = new int[m][2];
		
		for(int i = 0; i < m; i++) {
			tok = new StringTokenizer(br.readLine());
			pairs[i][0] = Integer.parseInt(tok.nextToken());
			pairs[i][1] = Integer.parseInt(tok.nextToken());
			pairToIndex.put(new Pair(pairs[i][0], pairs[i][1]), i);
		}
		
		PriorityQueue<Integer> pairID = new PriorityQueue<>(new SortingClass());
		
		for(int i = 0; i < m; i++) {
			pairID.add(i);
		}
		
		while(!pairID.isEmpty()) {
			int id = pairID.remove();
			int nastyaPosition = personToPosition.get(nastya);
			
			if(getMax(id) > nastyaPosition) {
				break;
			}
			
			int pos1 = personToPosition.get(pairs[id][0]);
			int pos2 = personToPosition.get(pairs[id][1]);
			if(pos2 == pos1 + 1) {
				array[pos1] = pairs[id][1];
				array[pos2] = pairs[id][0];
				personToPosition.put(pairs[id][0], pos2);
				personToPosition.put(pairs[id][1], pos1);
				if(pos1 > 0) {
					Pair p = new Pair(pos1 - 1, pos1);
					if(pairToIndex.containsKey(p)) {
						pairID.add(pairToIndex.get(p));
					}
				}
				if(pos2 > 0) {
					Pair p = new Pair(pos2 - 1, pos2);
					if(pairToIndex.containsKey(p)) {
						pairID.add(pairToIndex.get(p));
					}
				}
			}
		}
		
/*		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				int pos1 = personToPosition.get(pairs[j][0]);
				int pos2 = personToPosition.get(pairs[j][1]);
				if(pos2 == pos1 + 1) {
					personToPosition.put(pairs[j][0], pos2);
					personToPosition.put(pairs[j][1], pos1);
				}
			}
		}*/
		
		System.out.println(n - personToPosition.get(nastya));
		
		br.close();
	}
	
	public static int getMax(int id) {
		return Math.max(personToPosition.get(pairs[id][0]), personToPosition.get(pairs[id][1]));
	}
	
	public static int getMin(int id) {
		return Math.min(personToPosition.get(pairs[id][0]), personToPosition.get(pairs[id][1]));
	}
	
	public static class SortingClass implements Comparator<Integer> {
		
		@Override
		public int compare(Integer o1, Integer o2) {
			return getMin(o1) - getMin(o2);
		}
		
	}
	
	public static class Pair {
		public int a, b;
		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
		@Override
		public int hashCode() {
			return a * n + b;
		}
		@Override
		public boolean equals(Object o) {
			if(!(o instanceof Pair))
				return false;
			Pair p = (Pair) o;
			return p.a == a && p.b == b;
		}
	}
	
}
