#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> p(2 * n);
  for (int i = 0; i < (2 * n); ++i) cin >> p[i];
  vector<int> a(m), b(m);
  vector<int> other(2 * n, -1);
  vector<int> pnum(2 * n, -1);
  for (int i = 0; i < (m); ++i) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    if (p[a[i]] < p[b[i]]) swap(a[i], b[i]);
    other[a[i]] = b[i];
    other[b[i]] = a[i];
    pnum[a[i]] = i;
    pnum[b[i]] = i;
  }
  int t;
  cin >> t;
  int op_move = -1;
  int left = 2 * n;
  if (t == 2) {
    cin >> op_move;
    --op_move;
    --left;
  }
  vector<bool> used(m);
  vector<bool> avail(2 * n, true);
  while (left) {
    int j = -1;
    if (op_move != -1) {
      avail[op_move] = false;
      j = pnum[op_move];
    }
    int chosen = -1;
    if (j != -1 && avail[other[op_move]]) {
      used[j] = true;
      chosen = other[op_move];
    } else {
      int x = -1;
      for (int i = 0; i < (m); ++i)
        if (!used[i]) {
          x = i;
        }
      if (x != -1) {
        used[x] = true;
        chosen = a[x];
      } else {
        for (int i = 0; i < (2 * n); ++i)
          if (avail[i] && (chosen == -1 || p[i] > p[chosen])) {
            chosen = i;
          }
      }
    }
    avail[chosen] = false;
    --left;
    cout << chosen + 1 << "\n";
    cout.flush();
    if (left) {
      cin >> op_move;
      --op_move;
      --left;
    }
  }
}
