#include <bits/stdc++.h>
using namespace std;
int n, m, t, rep;
struct node {
  int x, sp, id;
};
vector<node> v;
vector<int> vis, vp;
node tmp;
bool opt(const node &a, const node &b) { return a.x > b.x; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  v.resize(2 * n);
  vp.resize(2 * n + 1);
  for (int i = 0; i < 2 * n; i++) {
    cin >> tmp.x;
    tmp.id = i + 1;
    v[i] = tmp;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a - 1].sp = b;
    v[b - 1].sp = a;
    vp[a] = b, vp[b] = a;
  }
  vis.resize(2 * n + 1);
  sort(v.begin(), v.end(), opt);
  cin >> t;
  if (t == 1) {
    int j = 0, p = 0;
    for (int i = 0; i < n; i++) {
      while (j < 2 * n && !(v[j].sp != 0 && vis[v[j].id] == 0)) j += 1;
      if (j >= 2 * n) {
        while (vis[v[p].id]) p += 1;
        cout << v[p].id << endl;
        cin >> rep;
        vis[v[p].id] = vis[rep] = 1;
      } else {
        cout << v[j].id << endl;
        cin >> rep;
        vis[v[j].id] = vis[rep] = 1;
      }
    }
  } else {
    int j = 0, p = 0;
    for (int i = 0; i < n; i++) {
      cin >> rep;
      vis[rep] = 1;
      if (vp[rep] != 0 && vis[vp[rep]] == 0) {
        cout << vp[rep] << endl;
        vis[vp[rep]] = 1;
        continue;
      }
      while (j < 2 * n && !(v[j].sp != 0 && vis[v[j].id] == 0)) j += 1;
      if (j >= 2 * n) {
        while (vis[v[p].id]) p += 1;
        cout << v[p].id << endl;
        vis[v[p].id] = 1;
      } else {
        cout << v[j].id << endl;
        vis[v[j].id] = 1;
      }
    }
  }
  return 0;
}
