#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m, a, b, p[N], u[N], mx, idx, t, c;
bool tkn[N];
void f() {
  for (;;) {
    mx = -1;
    idx = -1;
    for (int i = 1; i <= 2 * n; i++) {
      if (tkn[i]) continue;
      if (u[i] != -1) {
        if (p[i] > p[u[i]])
          idx = i;
        else
          idx = u[i];
        break;
      }
      if (mx < p[i]) {
        mx = p[i];
        idx = i;
      }
    }
    if (idx == -1) return;
    tkn[idx] = 1;
    cout << idx << "\n";
    cout.flush();
    cin >> idx;
    if (idx == -1) return;
    tkn[idx] = 1;
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> p[i];
    u[i] = -1;
    tkn[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    u[a] = b;
    u[b] = a;
  }
  cin >> t;
  if (t == 1) {
    f();
  } else {
    cin >> idx;
    if (idx == -1) return;
    tkn[idx] = 1;
    c = 1;
    while (u[idx] != -1) {
      idx = u[idx];
      tkn[idx] = 1;
      c++;
      cout << idx << "\n";
      cout.flush();
      if (c == 2 * n) break;
      cin >> idx;
      if (idx == -1) return;
      tkn[idx] = 1;
      c++;
    }
    if (c == 2 * n) return;
    f();
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
