1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define PB push_back
#define ALL(c) (c).begin(),(c).end()
#define INT(x) int x; scanf("%d", &x)

typedef vector<int> VI;
typedef vector<VI> VVI;

VVI t;
int ind[500000];

bool comp(int i, int j) {
	return t[i] < t[j];
}

int main() {
	INT(n);
	INT(m);
	t.resize(m);
	VI& a = t[0];
	a.resize(n);
	REP(i,n) scanf("%d", &a[i]);
	FOR(j,1,m) {
		t[j] = t[j-1];
		INT(p);
		scanf("%d", &t[j][p - 1]);
	}
	REP(j,m) ind[j] = j;
	stable_sort(ind, ind + m, comp);
	REP(j,m) {
		if (j) printf(" ");
		printf("%d", ind[j] + 1);
	}
	printf("\n");
}