#include <bits/stdc++.h>
struct node {
  int val;
  int idx;
};
void merging(struct node p[], int low, int mid, int high) {
  int l1, l2, i;
  struct node b[100005];
  for (l1 = low, i = low, l2 = mid + 1; l1 <= mid && l2 <= high; i++) {
    if (p[l1].val <= p[l2].val) {
      b[i] = p[l1++];
    } else {
      b[i] = p[l2++];
    }
  }
  while (l1 <= mid) {
    b[i++] = p[l1++];
  }
  while (l2 <= high) {
    b[i++] = p[l2++];
  }
  for (i = low; i <= high; i++) {
    p[i] = b[i];
  }
}
void sort(struct node p[], int low, int high) {
  int mid;
  if (low < high) {
    mid = (low + high) / 2;
    sort(p, low, mid);
    sort(p, mid + 1, high);
    merging(p, low, mid, high);
  }
}
int main() {
  int n, m, i, t, a[2005], cp[2005], s[2005], temp, pr[2005], count = 0;
  struct node p[2005];
  scanf("%d %d", &n, &m);
  for (i = 1; i <= 2 * n; i++) {
    scanf("%d", &p[i].val);
    s[i] = p[i].val;
    p[i].idx = i;
    cp[i] = 0;
    pr[i] = 0;
  }
  for (i = 1; i <= 2 * m; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &t);
  for (i = 1; i <= 2 * m; i++) {
    if (i % 2 == 0) {
      pr[a[i]] = a[i - 1];
    } else {
      pr[a[i]] = a[i + 1];
    }
  }
  sort(p, 1, 2 * n);
  if (t == 1) {
    for (i = 1; i <= 2 * m; i = i + 2) {
      if (s[a[i]] > s[a[i + 1]]) {
        cp[a[i]] = 1;
        printf("%d\n", a[i]);
      } else {
        cp[a[i + 1]] = 1;
        printf("%d\n", a[i + 1]);
      }
      fflush(stdout);
      scanf("%d", &temp);
      cp[temp] = 1;
    }
    for (i = 2 * n; i >= 1; i--) {
      if (cp[p[i].idx] == 0) {
        cp[p[i].idx] = 1;
        printf("%d\n", p[i].idx);
        fflush(stdout);
        scanf("%d", &temp);
        cp[temp] = 1;
      }
    }
  } else {
    while (count < 2 * n) {
      scanf("%d", &temp);
      count++;
      cp[temp] = 1;
      if (pr[temp] != 0) {
        cp[pr[temp]] = 1;
        count++;
        printf("%d\n", pr[temp]);
        fflush(stdout);
      } else {
        for (i = 1; i <= 2 * m; i += 2) {
          if (cp[a[i]] == 0) {
            cp[a[i]] = 1;
            count++;
            if (s[a[i]] > s[a[i + 1]]) {
              cp[a[i]] = 1;
              printf("%d\n", a[i]);
            } else {
              cp[a[i + 1]] = 1;
              printf("%d\n", a[i + 1]);
            }
            fflush(stdout);
            scanf("%d", &temp);
            cp[temp] = 1;
            count++;
          }
        }
        for (i = 2 * n; i >= 1; i--) {
          if (cp[p[i].idx] == 0) {
            cp[p[i].idx] = 1;
            count++;
            printf("%d\n", p[i].idx);
            fflush(stdout);
            if (count < 2 * n) {
              scanf("%d", &temp);
              cp[temp] = 1;
              count++;
            } else {
              exit(0);
            }
          }
        }
      }
    }
  }
}
