#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define float       long double
#define pb          push_back
#define ld          long double
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vpi         vector<pair<int,int> >
#define mii         map<int,int>
#define all(a)      (a).begin(),(a).end()
#define debug(x)    cout<<#x<<" is "<<(x)<<endl
#define mp          make_pair
#define x           first
#define y           second
#define pb          push_back
#define endl        '\n'
#define si(x)       (int)((x).size())
#define IOS         ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define txt         freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
int inf=99999999999;
const int mod=998244353 ;
const int cmp=1e17;
void inp(int *arr,int n)
{

    for(int i=0;i<n;i++) cin>>arr[i];
}
 main()
{
    IOS;
   int n,m;
   cin>>n>>m;
   int a[n];
   map<int,int>pos;
   vector<int> v;
   vector<int>in;
   f(i,0,n)
   {
       cin>>a[i];
       pos[a[i]]=i;
   }
   map<int ,int> ma;
   f(i,0,m)
   {
       int k,l;
       cin>>k>>l;
       ma[k*300000+l]=1;
       if(l==a[n-1])
        v.pb(pos[k]);
   }
   sort(v.rbegin(),v.rend());
   int arr[n+1];
   memset(arr,1,sizeof(arr));
   arr[a[n-1]]=0;
   int ans=0;
   for(int k:v)
   {
    //   debug(k);
       arr[a[k]]=0;
       int num=a[k];
    //   debug(num);
       for(int i=n-1;i>k;i--)
       {
      //     debug(i);
           int t=a[i];
       //    debug(t);
        if(arr[t])
           {
        //       debug(t);
            if(ma.find(num*300005+t)==ma.end())
               {
                arr[a[k]]=1;
                break;
               }
           }
       }
       if(arr[a[k]]==0)
       ans++;
   }
   cout<<ans;
//
//}
//main()
//{
//
//    IOS;
////    int t;
////    cin>>t;
////    while(t--)
//    solve();


    return 0;
}
