#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define pb push_back
#define ins insert
#define fi first
#define se second
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define intt long long
const intt mod = 1e9 + 7;
const intt base = 9973;
const intt inf = 1e18;
const intt mxN = 5e5 + 5;
const intt L = 21;
void solve() {
	intt N, R, K;
	cin >> N >> K >> R;
	vector<intt> A(N);
	for(auto &a : A) cin >> a;
	vector<intt> REQ(K, 0ll);
	set<intt> st;
	for(intt i = 0; i < R; i++) {
		intt num, val;
		cin >> num >> val;
		REQ[num] = val;
		st.insert(num);
	}
	
	intt ans = inf;
	for(intt i = 0; i < N; i++){
		for(intt j = i; j < N; j++) {
			vector<intt> cnt(K, 0ll);
			for(intt k = i; k <= j; k++) {
				cnt[A[k]]++;
			}
			intt fl = 1;
			for(intt eded : st) {
				if(cnt[eded] < REQ[eded]) {
					fl = 0;
					break;
				}
			}
			if(fl) {
				ans = min(ans, j - i + 1);
			}
		}
	}
	if(ans == inf) {
		cout << "impossible" << endl;
		return;
	}
	cout << ans << endl;
}
signed main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(NULL);                
	cout.tie(NULL);
	intt tst = 1;
	// cin >> tst;
	while(tst--) {
		solve();
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |