#include <bits/stdc++.h>
using namespace std;
int main() {
int N,M;
cin >> N;
vector<int> A(N);
map<int,int> C;
for(int i =0; i < N; i++) {
cin >> A[i];
C[A[i]] +=1;}
if(C.size() == 1) {cout << "0\n"; return 0;}
cin >> M;
for(int i =0; i < M; i++) {
int x,y;
cin >> x >> y;
x--;
C[A[x]] -=1;
C[y] +=1;
A[x] =y;
if(C[y] == N) {cout << i+1 << "\n"; return 0;}
}
cout << "-1\n";
return 0;}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBOLE07CgljaW4gPj4gTjsKCXZlY3RvcjxpbnQ+IEEoTik7CgltYXA8aW50LGludD4gQzsKCWZvcihpbnQgaSA9MDsgaSA8IE47IGkrKykgewoJCWNpbiA+PiBBW2ldOwoJCUNbQVtpXV0gKz0xO30KCWlmKEMuc2l6ZSgpID09IDEpIHtjb3V0IDw8ICIwXG4iOyByZXR1cm4gMDt9CgljaW4gPj4gTTsKCWZvcihpbnQgaSA9MDsgaSA8IE07IGkrKykgewoJCWludCB4LHk7CgkJY2luID4+IHggPj4geTsKCQl4LS07CgkJQ1tBW3hdXSAtPTE7CgkJQ1t5XSArPTE7CgkJQVt4XSA9eTsKCQlpZihDW3ldID09IE4pIHtjb3V0IDw8IGkrMSA8PCAiXG4iOyByZXR1cm4gMDt9CgkJfQoJY291dCA8PCAiLTFcbiI7CglyZXR1cm4gMDt9