#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
bool f[1000003];
long long a[1000003];
long long X[1000003], Y[1000003];
long long C = 0;
long long F[1000003];
struct cmp {
  bool operator()(const long long& x, const long long& y) {
    return (a[x] > a[y]) || (a[x] == a[y] && x < y);
  }
};
set<long long, cmp> s;
signed main() {
  long long n = read(), m = read();
  for (long long i = 1; i <= n * 2; ++i) a[i] = read();
  for (long long i = 1; i <= m; ++i) {
    long long A = read(), B = read();
    X[++C] = A, Y[C] = B;
    F[A] = B, F[B] = A;
  }
  long long op = read();
  if (op == 1) {
    for (long long i = 1; i <= C; ++i) {
      if (a[X[i]] >= a[Y[i]])
        printf("%lld ", X[i]);
      else
        printf("%lld ", Y[i]);
      puts("");
      fflush(stdout);
      read();
      f[X[i]] = f[Y[i]] = 1;
    }
    for (long long i = 1; i <= 2 * n; ++i) {
      if (!f[i]) s.insert(i);
    }
    while (!s.empty()) {
      long long A = *(s.begin());
      s.erase(s.begin());
      printf("%lld\n", A);
      fflush(stdout);
      long long B = read();
      s.erase(B);
    }
  } else {
    long long D = 0, G = 0;
    while (1) {
      long long x = read();
      f[x] = 1;
      if (F[x]) {
        ++G, printf("%lld\n", F[x]), f[F[x]] = 1, fflush(stdout), ++D;
        if (G == n) return 0;
      } else
        break;
    }
    for (long long i = 1; i <= C; ++i)
      if (!f[X[i]]) {
        if (a[X[i]] >= a[Y[i]])
          printf("%lld ", X[i]);
        else
          printf("%lld ", Y[i]);
        puts("");
        fflush(stdout);
        ++G;
        if (G == n) return 0;
        read();
        f[X[i]] = f[Y[i]] = 1;
      }
    for (long long i = 1; i <= 2 * n; ++i) {
      if (!f[i]) s.insert(i);
    }
    while (!s.empty()) {
      long long A = *(s.begin());
      s.erase(s.begin());
      printf("%lld\n", A);
      fflush(stdout);
      if (G == n) return 0;
      if (s.empty()) break;
      long long B = read();
      s.erase(B);
    }
  }
  return 0;
}
