#include <bits/stdc++.h>
using namespace std;
int n, m, p[100005], to[100005];
bool u[100005];
vector<pair<int, int>> v;
priority_queue<pair<int, int>> q;
bool o;
int ta, tb;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n * 2; i++) scanf("%d", p + i);
  while (m--) {
    scanf("%d%d", &ta, &tb);
    to[ta] = tb;
    to[tb] = ta;
    if (p[tb] > p[ta]) swap(ta, tb);
    v.emplace_back(ta, tb);
  }
  for (int i = 1; i <= n * 2; i++)
    if (!to[i]) q.emplace(p[i], i);
  scanf("%d", &ta);
  if (ta == 1) {
    for (int i = 0; i < n; i++) {
      o = 0;
      while (!v.empty()) {
        if (u[v.back().second]) {
          v.pop_back();
          continue;
        }
        o = 1;
        printf("%d\n", v.back().first);
        u[v.back().first] = 1;
        v.pop_back();
        break;
      }
      if (!o) {
        while (1) {
          if (u[q.top().second]) {
            q.pop();
            continue;
          }
          printf("%d\n", q.top().second);
          u[q.top().second] = 1;
          q.pop();
          break;
        }
      }
      fflush(stdout);
      scanf("%d", &ta);
      u[ta] = 1;
    }
  } else {
    for (int i = 0; i < n; i++) {
      scanf("%d", &ta);
      u[ta] = 1;
      if (to[ta] && !u[to[ta]]) {
        printf("%d\n", to[ta]);
        u[to[ta]] = 1;
      } else {
        o = 0;
        while (!v.empty()) {
          if (u[v.back().second]) {
            v.pop_back();
            continue;
          }
          o = 1;
          printf("%d\n", v.back().first);
          u[v.back().first] = 1;
          v.pop_back();
          break;
        }
        if (!o) {
          while (1) {
            if (u[q.top().second]) {
              q.pop();
              continue;
            }
            printf("%d\n", q.top().second);
            u[q.top().second] = 1;
            q.pop();
            break;
          }
        }
      }
      fflush(stdout);
    }
  }
  return 0;
}
