#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7
constexpr int H = 24;


int main()
{
	while (true) {
		int T, N;
		cin >> T;
		if (!T)break;
		vector<int> t(T);
		REP(i, T)cin >> t[i];
		cin >> N;
		vector<pair<int, int>> dm(N);
		REP(i, N) {
			int d, m;
			cin >> d >> m;
			dm[i] = { d - 1,m };
		}
		sort(dm.begin(), dm.end());

		int day = 0;
		for (auto p : dm)day = max(day, p.first);
		vector<vector<int>> dp(day + 1, vector<int>(T, INF));
		dp[0][0] = 0;
		FOR(i, 1, day + 1) {
			FOR(j, 1, T)dp[i][j] = dp[i - 1][j - 1];
			dp[i][0] = *min_element(dp[i - 1].begin(), dp[i - 1].end()) + 1;
			dp[i][0] = min(dp[i][0], dp[i - 1].back());
			for (auto p : dm)if (p.first == i) {
				REP(j, T)if (t[j] > p.second)dp[i][j] = INF;
			}
		}
		cout << *min_element(dp.back().begin(), dp.back().end()) << endl;
	}
	return 0;
}

