import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int pairs = scanner.nextInt();
        int a[] = new int[n];
        for(int ppl = 0; ppl < n; ppl++) {
            a[ppl] = scanner.nextInt();
        }
        int res = 0;
        for(int pair = 0; pair < pairs; pair++) {
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            int p1 = elementPosition(a, u);
            int p2 = elementPosition(a, v);
            if(p1 != -1 && p2 != -1 && p1+1 == p2){
                res++;
            }
        }
        
        System.out.println(res);
    }
    public static int elementPosition(int a[], int key) {
        for(int i = 0; i < a.length; i++) {
            if(a[i] == key){
                return i;
            }
        }
        return -1;
    }
}