#include <bits/stdc++.h>

const int N = 300000;
const int INF = 1<<30;

inline int read()
{
	char c = getchar(); int f = 1, x = 0;
	while( c < '0' || c>'9' ) { if(c == '-') f = -1;  c = getchar(); }
	while( c >= '0'&&c<='9' ) { x = x * 10 + c - '0'; c = getchar(); }
	return f * x;
}

int n, m, b[N], sum0[N], sum1[N]; 

std::pair <int, int> q[N];

std::vector <int> v[N];

inline void ck_min( int &a, int b ) { if ( a > b ) a = b; }

struct segment_tree {
    int val[N<<2], opt[N<<2];
    #define lson (o<<1)
    #define rson (o<<1|1)
    inline void pushup( int o ) { val[o] = std::min( val[lson], val[rson] ); }
    inline void pushdown( int o, int l, int r )
    {
        if( !opt[o] || l == r ) return;

        val[lson] += opt[o]; opt[lson] += opt[o]; 
        val[rson] += opt[o]; opt[rson] += opt[o];
        opt[o] = 0;
    }
    inline void clear( int o, int l, int r )
    {
        opt[o] = 0; val[o] = INF; 
        if( l == r ) return;
        int mid = l + r >> 1;

        clear( lson, l, mid );
        clear( rson,mid+1,r ); 
    }
    inline void insert( int o, int l, int r, int pos, int x )
    {
        if( l == r ) {
            val[o] = std::min( val[o], x ); return;
        }
        pushdown( o, l, r );
        int mid = l + r >> 1;

        if( pos <= mid ) insert( lson, l, mid, pos, x );
        else insert( rson, mid+1, r, pos, x );
        pushup( o );
    }
    inline void modify( int o, int l, int r, int ql, int qr, int x )
    {
        if( ql > qr ) return;
        if( ql <= l && r <= qr ) {
            opt[o] += x; val[o] += x; return;
        }
        pushdown( o, l, r );
        int mid = l + r >> 1;
    
        if( ql <= mid ) modify( lson, l, mid, ql, qr, x );
        if( mid+1<=qr ) modify( rson,mid+1,r, ql, qr, x );
        pushup( o );
    }
    inline int query( int o, int l, int r, int ql, int qr )
    {
        if( ql > qr ) return INF;
        if( ql <= l && r <= qr ) return val[o];

        pushdown( o, l, r );
        int mid = l + r >> 1, ret = INF; 

        if( ql <= mid ) ck_min( ret, query( lson, l, mid, ql, qr ) );
        if( mid+1<=qr ) ck_min( ret, query( rson,mid+1,r, ql, qr ) );
        pushup( o ); return ret;
    }
    #undef lson
    #undef rson
} seg;

int main()
{
    n = read(); 
    for( int i = 1; i <= n; i ++ )
        b[i] = read();
    
    for( int i = 1; i <= n; i ++ )
        sum0[i] = sum0[i-1] + ( b[i] == 0 ),
        sum1[i] = sum1[i-1] + ( b[i] == 1 );

    m = read();
    for( int i = 1; i <= m; i ++ )
        { q[i].first = read(); q[i].second = read(); }

    sort( q+1, q+1+m );

    for( int i = 1; i <= m; i ++ )
        v[q[i].first].push_back( q[i].second );
    
    seg.clear( 1, 0, n );
    seg.insert( 1, 0, n, 0, 0 );
    
    for( int i = 1; i <= n; i ++ )
    {
        int lim = v[i].size();
        for( int j = 0; j < lim; j ++ )
            seg.insert( 1, 0, n, v[i][j], seg.query( 1, 0, n, 0, v[i][j] ) );
            // f[i][r] = min( f[i-1][k] ), k \in [0, r]

        if( sum1[i] != sum1[i-1] ) seg.modify( 1, 0, n, 0, i-1, 1 );
        else seg.modify( 1, 0, n, 0, i-1, -1 );
        // 给 i 为 0 的结点加上贡献 
    }

    printf( "%d\n", seg.query( 1, 0, n, 0, n ) + sum0[n] );

    return 0;
}

Measured memory_bytes: 25728