import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Objects;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DNastyaIsBuyingLunch solver = new DNastyaIsBuyingLunch();
        solver.solve(1, in, out);
        out.close();
    }

    static class DNastyaIsBuyingLunch {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            Debug debug = new Debug();
            int n = in.nextInt();
            int m = in.nextInt();
            int[] p = in.nextIntArray(n);
            MiscUtils.decreaseByOne(p);
            Set<DNastyaIsBuyingLunch.Pair> set = new HashSet<>();
            DJSet djSet = new DJSet(n);
            for (int i = 0; i < m; ++i) {
                int u = in.nextInt() - 1;
                int v = in.nextInt() - 1;
                int uu = Math.min(u, v);
                int vv = Math.max(u, v);
                set.add(new DNastyaIsBuyingLunch.Pair(uu, vv));
                djSet.union(uu, vv);
            }
            for (int i = 0; i + 1 < n; ++i) {
                if (!djSet.equiv(p[i], p[n - 1])) continue;
                int ptr = i + 1;
                while (ptr < n - 1) {
                    int p1 = Math.min(p[i], p[ptr]);
                    int p2 = Math.max(p[i], p[ptr]);
                    if (set.contains(new DNastyaIsBuyingLunch.Pair(p1, p2))) {
                        ++ptr;
                    } else break;
                }
                --ptr;
                int t = p[i];
                p[i] = p[ptr];
                p[ptr] = t;
            }
            int last = n - 2;
            int step = 0;
            while (last >= 0) {
                int p1 = Math.min(p[n - 1], p[last]);
                int p2 = Math.max(p[n - 1], p[last]);
                if (set.contains(new DNastyaIsBuyingLunch.Pair(p1, p2))) {
                    --last;
                    ++step;
                } else break;
            }
            out.println(step);
        }

        static class Pair {
            int from;
            int to;

            public Pair(int f, int t) {
                from = f;
                to = t;
            }

            public boolean equals(Object o) {
                if (this == o) return true;
                if (o == null || getClass() != o.getClass()) return false;
                DNastyaIsBuyingLunch.Pair pair = (DNastyaIsBuyingLunch.Pair) o;
                return from == pair.from &&
                        to == pair.to;
            }

            public int hashCode() {
                return Objects.hash(from, to);
            }

            public String toString() {
                return "Pair{" +
                        "from=" + (from + 1) +
                        ", to=" + (to + 1) +
                        '}';
            }

        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

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

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

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

    }

    static class Debug {
        PrintWriter out;
        boolean oj;
        long timeBegin;
        Runtime runtime;

        public Debug(PrintWriter out) {
            oj = System.getProperty("ONLINE_JUDGE") != null;
            this.out = out;
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

        public Debug() {
            oj = System.getProperty("ONLINE_JUDGE") != null;
            OutputStream outputStream = System.err;
            this.out = new PrintWriter(outputStream);
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

        public void finalize() {
            out.flush();
            out.close();
        }

    }

    static class MiscUtils {
        public static void decreaseByOne(int[]... arrays) {
            for (int[] array : arrays) {
                for (int i = 0; i < array.length; i++) {
                    array[i]--;
                }
            }
        }

    }

    static class DJSet {
        public int[] upper;
        public int count;

        public DJSet(int n) {
            upper = new int[n];
            count = n;
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
                --count;
                return true;
            }
            return false;
        }

    }
}

