import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigInteger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeSet;

public final class CF_546_D2_D
{


	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
	static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}

	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}


	static int[] cache;

	static int OK=1;
	static int KO=2;

	static int[] moved;

	static void moveOld(int i,int[] p,TreeSet<Integer>[] friends) {
		moved[i]=p[i];
		if (i==0)
			return;
		//log("i:"+i);
	
		boolean goon=true;
	
		while (i>0 && goon) {
			goon=false;
			int u=p[i];
			int v=p[i-1];
			if (friends[u].contains(v)) {
				p[i]=v;
				p[i-1]=u;
				moved[i-1]=u;
				goon=true;
				i--;
			} else {
				if (moved[i-1]!=v) {
					goon=true;
					moveOld(i-1,p,friends);
					//log("bob");
				}
			}
		}
		return;
	}
	
	static void moveStack(int x,int[] p,TreeSet<Integer>[] friends,int me) {
		moved[x]=p[x];
		if (x==0)
			return;
		int n=p.length;
		int[] stack=new int[n];
		int st=0;
		stack[st++]=x;
		while (st>0) {
			int i=stack[st-1];
			if (i==0) {
				st--;
			} else {
				int u=p[i];
				int v=p[i-1];
				if (friends[u].contains(v)) {
					p[i]=v;
					p[i-1]=u;
					moved[i-1]=u;
					i--;
					if (u==me)
						stack[st-1]=i;
					else
						st--;
				} else {
					if (moved[i-1]!=v) {
						moved[i-1]=v;
						stack[st++]=i-1;
					} else {
						st--;
					}
				}
			}
		}

	}


	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static void process() throws Exception {

		//test();

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader = new InputReader(System.in);


		int n=reader.readInt();
		int m=reader.readInt();
		int[] p=new int[n];
		for (int i=0;i<n;i++)
			p[i]=reader.readInt()-1;
		TreeSet<Integer>[] friends=new TreeSet[n];
		for (int u=0;u<n;u++)
			friends[u]=new TreeSet<Integer>();
		for (int i=0;i<m;i++) {
			int u=reader.readInt()-1;
			int v=reader.readInt()-1;
			friends[v].add(u);
		}

		cache=new int[n];
		moved=new int[n];
		Arrays.fill(moved, -1);
		int me=p[n-1];
		//moveOld(n-1,p,friends);
		moveStack(n-1,p,friends,me);
		int ans=0;
		for (int i=0;i<n;i++) {
			if (p[i]==me) {
				ans=(n-1-i);
			}
		}

		output(ans);
		try {
			out.close();
		} catch (Exception e) {
		}

	}

	public static void main(String[] args) throws Exception {
		process();

	}

	static final class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.append((char) c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg = false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d = (char) c;
			// log("d:"+d);
			if (d == '-') {
				neg = true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			// log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
	}

}