#include <bits/stdc++.h>
using namespace std;
const int N = 2047;
int n, m, p[N], a[N], q[N], vis[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2 * n; ++i) scanf("%d", &p[q[i] = i]);
  for (int i = 1, x, y; i <= m; ++i) scanf("%d%d", &x, &y), a[a[x] = y] = x;
  sort(q + 1, q + 2 * n + 1, [](int x, int y) -> bool {
    return a[x] && !a[y] ? 1 : !a[x] && a[y] ? 0 : p[x] > p[y];
  });
  scanf("%d", &m);
  if (m == 1) printf("%d\n", vis[q[1]] = q[1]), fflush(stdout);
  for (int t = 1;;) {
    scanf("%d", &m);
    for (vis[m] = m; vis[q[t]]; t++)
      ;
    if (t > 2 * n) break;
    m = a[m] && !vis[a[m]] ? a[m] : q[t];
    printf("%d\n", vis[m] = m), fflush(stdout);
  }
}
