#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> A;
vector<pair<int, int> > M;
vector<int> PP;
int turn;
set<int> Go;
int ans(int x) {
  cout << x + 1 << endl;
  if (Go.empty()) exit(0);
  cin >> x;
  return x - 1;
}
signed main() {
  ;
  cin >> n >> m;
  A.resize(n << 1);
  for (auto &x : A) cin >> x;
  M.resize(m);
  for (auto &x : M) cin >> x.first >> x.second, x.first--, x.second--;
  PP.assign(n << 1, -1);
  for (auto x : M) PP[x.first] = x.second, PP[x.second] = x.first;
  for (int i = 0; i < n << 1; i++) {
    Go.insert(i);
  }
  cin >> turn;
  if (turn == 1) {
    for (auto x : M) {
      if (A[x.first] > A[x.second]) {
        ans(x.first);
        Go.erase(x.first);
        Go.erase(x.second);
      } else {
        ans(x.second);
        Go.erase(x.first);
        Go.erase(x.second);
      }
    }
    while (Go.size()) {
      int mx = -1, r = -1;
      for (auto &x : Go) {
        if (mx < A[x]) mx = A[x], r = x;
      }
      Go.erase(r);
      Go.erase(ans(r));
    }
  } else {
    int x;
    cin >> x;
    x--;
    Go.erase(x);
    while (PP[x] != -1) {
      Go.erase(PP[x]);
      x = ans(PP[x]);
      Go.erase(x);
    }
    for (auto x : M) {
      if (!Go.count(x.first)) continue;
      if (A[x.first] > A[x.second]) {
        ans(x.first);
        Go.erase(x.first);
        Go.erase(x.second);
      } else {
        ans(x.second);
        Go.erase(x.first);
        Go.erase(x.second);
      }
    }
    while (Go.size()) {
      int mx = -1, r = -1;
      for (auto &x : Go) {
        if (mx < A[x]) mx = A[x], r = x;
      }
      Go.erase(r);
      Go.erase(ans(r));
    }
  }
}
