#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> p(2 * n + 1);
  set<pair<int, int>, greater<pair<int, int>>> ord;
  for (int i = 0; i < 2 * n; i++) {
    cin >> p[i + 1];
    ord.insert({p[i + 1], i + 1});
  }
  map<int, int> dep;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    dep.insert({a, b});
    dep.insert({b, a});
  }
  int t;
  cin >> t;
  int nec = -1;
  for (int i = 0; i < 2 * n; i++) {
    if (t == 1) {
      if (nec < 0) {
        if (((int)dep.size()) == 0) {
          cout << (ord.begin())->second << endl;
          ord.erase(ord.begin());
        } else {
          int aux;
          auto it = dep.begin();
          if (p[it->first] > p[it->second])
            aux = it->first;
          else
            aux = it->second;
          cout << aux << endl;
          nec = -2;
          ord.erase({p[aux], aux});
          dep.erase(dep[aux]);
          dep.erase(aux);
        }
      } else {
        cout << nec << endl;
        dep.erase(nec);
        ord.erase({p[nec], nec});
        nec = -1;
      }
      t = 2;
    } else {
      int x;
      cin >> x;
      ord.erase({p[x], x});
      if (dep.count(x)) {
        nec = dep[x];
        dep.erase(x);
      }
      t = 1;
    }
  }
  return 0;
}
