    /*
    *****************************************************
    *  Author-> PC_2.0                                  *
    *  College-> Birla Institute Of Technology Mesra    *
    *  Branch-> Computer Science And Engineering        *
    *****************************************************
    */
    #include<bits/stdc++.h>
    # define NDEBUG
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long int
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define ff first
    #define ss second
    #define in insert
    #define si size()
    int M=1000000007;
    #define siz 1000005
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
    vector<ll> z;
    //////////////////////////////////////////////////MATHS_FUNCTIONS//////////////////////////////////////////////////
    ll poww(ll i,ll j,ll m)
    {
        ll ans=1;
        while(j>0)
        {
            if(j%2!=0)
                ans=(ans*i)%m;
            i=(i*i)%m;
            j/=2;
        }
        return ans%m;
    }
    ll powww(ll i,ll j)
    {
        ll ans=1;
        while(j>0)
        {
            if(j%2!=0)
                ans=(ans*i);
            i=(i*i);
            j/=2;
        }
        return ans;
    }
    ll gcd(ll i,ll j)
    {
        if(j==0)
            return i;
        else
            return gcd(j,i%j);
    }
    ll lcm(ll i,ll j)
    {
        return (i*j)/gcd(i,j);
    }
    ll phi(ll i)
    {
        double result=i;
        for(ll j=2;j*j<=i;++j)
        {
            if(i%j==0)
            {
                while(i%j==0)
                    i/=j;
                result*=(1.0-1.0/((double)j));
            }
        }
        if(i>1)
            result*=(1.0-1.0/((double)i));
        return (int)result;
    }
    void primeFactors(ll i)
    {
        while(i%2==0)
        {
            z.pb(2);
            i/=2;
        }
        for(ll j=3;j<=sqrt(i);j+=2)
        {
            while(i%j==0)
            {
                z.pb(j);
                i/=j;
            }
        }
        if(i>2)
            z.pb(i);
    }
    void printDivisors(ll n)
    {
        for (ll i=1; i<=sqrt(n); i++)
        {
            if (n%i == 0)
            {
                if (n/i == i)
                    z.pb(i);
                else
                    {
                        z.pb(i);
                        z.pb(n/i);
                    }
            }
        }
    }
    class compare
    {
    public:
    bool operator()(pair<ll,pair<ll,ll> > a,pair<ll,pair<ll,ll> > b)
    {
        if(a.ff>b.ff)
            return false;
        else if(a.ff==b.ff && a.ss.ff<b.ss.ff)
            return false;
        else
            return true;
    }
    };
    bool comp(ll a,ll b)
    {
        if(a>b)
        return true;
        else
        return false;
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        ll i,j;
        cin>>i>>j;
        ll a[i];
        for(ll k=0;k<i;++k)
            cin>>a[k];
        set<pair<ll,ll> > s;
        for(ll k=0;k<j;++k)
        {
            ll l,m;
            cin>>l>>m;
            s.in({l,m});
        }
        ll ans=0;
        for(ll k=0;k<i-1;++k)
        {
            if(s.count({a[k],a[k+1]}))
                ++ans;
        }
        cout<<ans;
        return 0;
    }
