#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e5 + 228;
const char nxtl = '\n';
const int mod = (int)1e9 + 7;
const double eps = (double)1e-7;
template <typename T>
inline bool updmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool updmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int n, m, t;
int a[MAXN], id[MAXN];
int p[MAXN];
set<pair<int, int>> s;
bool used[MAXN];
inline bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  unsigned int FOR;
  asm("rdtsc" : "=A"(FOR));
  srand(FOR);
  cin >> n >> m;
  for (int i = 1; i <= (n << 1); ++i) {
    id[i] = i;
    cin >> a[i];
  }
  sort(id + 1, id + (n << 1) + 1, &cmp);
  for (int i = 1; i <= m; ++i) {
    int A, B;
    cin >> A >> B;
    p[A] = B;
    p[B] = A;
    if (a[A] < a[B]) swap(A, B);
    s.insert({A, B});
  }
  cin >> t;
  if (t == 1) {
    int lst = (n << 1);
    for (int i = 1; i <= n; ++i) {
      int myans = 0;
      while (lst > 0 && used[id[lst]]) --lst;
      if (!s.empty()) {
        myans = (*--s.end()).first;
        s.erase(--s.end());
      } else
        myans = id[lst];
      cout << myans << endl;
      int x;
      cin >> x;
      used[x] = used[myans] = 1;
    }
  } else {
    int lst = (n << 1);
    for (int i = 1; i <= n; ++i) {
      int x;
      cin >> x;
      used[x] = 1;
      if (p[x] && !used[p[x]]) {
        cout << p[x] << endl;
        used[p[x]] = 1;
        s.erase({x, p[x]});
        s.erase({p[x], x});
        continue;
      }
      int myans = 0;
      while (lst > 0 && used[id[lst]]) --lst;
      if (!s.empty()) {
        myans = (*--s.end()).first;
        s.erase(--s.end());
      } else
        myans = id[lst];
      cout << myans << endl;
      used[myans] = 1;
    }
  }
  return 0;
}
