#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 6;
const int N = 5e3 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f3f3f3f3f;
int n, m, p[maxn], id[maxn], vis[maxn], idx[maxn];
pair<int, int> a[maxn];
bool cmp(int x, int y) { return p[x] < p[y]; }
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &p[i]);
    id[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    idx[a[i].first] = a[i].second;
    idx[a[i].second] = a[i].first;
  }
  sort(id + 1, id + 1 + 2 * n, cmp);
  int t, x;
  scanf("%d", &t);
  if (t == 1) {
    int cnt = 2 * n;
    for (int i = 1; i <= m; i++) {
      if (p[a[i].second] > p[a[i].first]) {
        printf("%d\n", a[i].second);
      } else
        printf("%d\n", a[i].first);
      fflush(stdout);
      scanf("%d", &x);
      vis[a[i].second] = vis[a[i].first] = 1;
    }
    cnt -= 2 * m;
    int i = 2 * n;
    while (cnt) {
      for (; vis[id[i]]; i--)
        ;
      printf("%d\n", id[i]);
      vis[id[i]] = 1;
      fflush(stdout);
      scanf("%d", &x);
      vis[x] = 1;
      cnt -= 2;
    }
  } else {
    int cnt = 2 * n;
    while (1) {
      scanf("%d", &x);
      vis[x] = 1;
      cnt--;
      if (cnt == 0) break;
      if (idx[x]) {
        printf("%d\n", idx[x]);
        fflush(stdout);
        vis[x] = 1;
        vis[idx[x]] = 1;
        cnt--;
        if (cnt == 0) break;
      } else {
        for (int i = 1; i <= m; i++) {
          if (vis[a[i].second]) continue;
          if (p[a[i].second] > p[a[i].first]) {
            printf("%d\n", a[i].second);
          } else
            printf("%d\n", a[i].first);
          fflush(stdout);
          scanf("%d", &x);
          vis[a[i].second] = 1;
          vis[a[i].first] = 1;
          cnt -= 2;
        }
        int i = 2 * n;
        while (cnt > 0) {
          for (; vis[id[i]]; i--)
            ;
          vis[id[i]] = 1;
          printf("%d\n", id[i]);
          cnt--;
          fflush(stdout);
          if (cnt == 0) break;
          scanf("%d", &x);
          vis[x] = 1;
          cnt--;
        }
        break;
      }
    }
  }
}
