#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  set<pair<int, int>> ps;
  vector<int> po(2 * n), sc(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    cin >> po[i];
    sc[i] = po[i];
  }
  map<int, int> opp;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    opp[a] = b;
    opp[b] = a;
    if (po[a] < po[b]) swap(a, b);
    sc[a] = 1e6 + (po[a] - po[b]);
  }
  for (int i = 0; i < 2 * n; i++) {
    ps.insert({-sc[i], i});
  }
  int t, la = -1;
  cin >> t;
  for (int i = 0; i < 2 * n; i++) {
    if (t == 1) {
      if (opp.find(la) != opp.end() and
          ps.find({-sc[opp[la]], opp[la]}) != ps.end())
        la = opp[la];
      else
        la = ps.begin()->second;
      cout << la + 1 << endl;
      cout.flush();
    } else {
      cin >> la;
      la--;
    }
    assert(ps.find({-sc[la], la}) != ps.end());
    ps.erase({-sc[la], la});
    t = 3 - t;
  }
  return 0;
}
