import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
}

void main() {
  auto r = new InputReader;
  immutable int n = r.next!uint;
  immutable int m = r.next!uint;
  auto p = uninitializedArray!(int[]) (n);
  auto pos = uninitializedArray!(int[]) (n + 1);
  foreach (i; 0 .. n) {
    p[i] = r.next!uint;
    pos[p[i]] = i;
  }
  auto e = new int[][n+1];
  foreach (edgeid; 0 .. m) {
    immutable i = r.next!uint;
    immutable j = r.next!uint;
    e[i] ~= j;
  }
  debug stderr.writeln (e);
  int res;
  auto d = new bool[n+1];
  int l = 1;
  foreach_reverse (i; 0 .. n - 1) {
    int cnt;
    immutable pi = p[i];
    immutable pk = pos[pi];
    foreach (j; e[pi]) {
      if (!d[j] && pk < pos[j]) ++cnt;
    }
    debug stderr.writeln (cnt, ' ', l);
    if (cnt == l) {
      ++res;
      d[pi] = true;
    } else {
      ++l;
    }
  }
  write (res);
}
