#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e3 + 10;
int force[MAX], special[MAX];
set<pair<int, int>> queue_special, queue_greater;
int query(int k) {
  printf("%d\n", k);
  fflush(stdout);
  int got;
  scanf("%d", &got);
  if (got == -1) exit(0);
  return got;
}
int queryy() {
  int got;
  scanf("%d", &got);
  return got;
}
int who() {
  if (!queue_special.empty()) {
    int best_special = queue_special.begin()->second;
    queue_special.erase(queue_special.begin());
    return best_special;
  }
  int best_greater = queue_greater.begin()->second;
  queue_greater.erase(queue_greater.begin());
  return best_greater;
}
void erase(int x) {
  for (auto i : queue_special)
    if (i.second == x) {
      queue_special.erase(i);
      return;
    }
  for (auto i : queue_greater)
    if (i.second == x) {
      queue_greater.erase(i);
      return;
    }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= 2 * n; i++) scanf("%d", force + i);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    special[a] = b;
    special[b] = a;
  }
  for (int i = 1; i <= 2 * n; i++)
    if (!special[i])
      queue_greater.insert({-force[i], i});
    else
      queue_special.insert({-force[i], i});
  int t;
  scanf("%d", &t);
  int jogadas = 0;
  bool mefudi = false;
  int carai;
  if (t == 2) {
    carai = queryy();
    if (special[carai]) mefudi = true;
    erase(carai);
    jogadas = 1;
  }
  while (jogadas != 2 * n) {
    int next;
    if (mefudi == false)
      next = who();
    else {
      next = special[carai];
      erase(next);
    }
    jogadas++;
    if (jogadas == 2 * n) {
      printf("%d\n", next);
      return 0;
    }
    carai = query(next);
    if (special[carai] && mefudi == true)
      mefudi = true;
    else
      mefudi = false;
    erase(carai);
    jogadas++;
  }
  return 0;
}
