#include <bits/stdc++.h>
using namespace std;
struct Hero {
  int strength, place;
  bool used = false;
};
bool cmp(const Hero &a, const Hero &b) { return a.strength > b.strength; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<Hero> v(2 * n);
  vector<int> places(2 * n);
  vector<int> pairs(2 * m);
  map<int, int> pairmap;
  for (int i = 0; i < 2 * n; i++) {
    cin >> v[i].strength;
    v[i].place = i;
  }
  for (int i = 0; i < 2 * m; i += 2) {
    cin >> pairs[i] >> pairs[i + 1];
    pairs[i]--;
    pairs[i + 1]--;
    pairmap[pairs[i + 1]] = pairs[i];
    pairmap[pairs[i]] = pairs[i + 1];
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < 2 * n; i++) {
    places[v[i].place] = i;
  }
  int t;
  cin >> t;
  int k = 1;
  if (t == 2) {
    int x;
    cin >> x;
    x--;
    v[places[x]].used = true;
    while (pairmap.count(x)) {
      cout << pairmap[x] + 1 << endl;
      v[places[pairmap[x]]].used = true;
      if (k == n) break;
      cin >> x;
      x--;
      k++;
      v[places[x]].used = true;
    }
  }
  for (int i = 0; i < 2 * m; i += 2) {
    int x;
    if (v[places[pairs[i]]].used) {
      continue;
    }
    if (v[places[pairs[i]]].strength > v[places[pairs[i + 1]]].strength) {
      cout << pairs[i] + 1 << endl;
    } else {
      cout << pairs[i + 1] + 1 << endl;
    }
    cin >> x;
    v[places[pairs[i]]].used = true;
    v[places[pairs[i + 1]]].used = true;
  }
  int cur = 0;
  while (cur < 2 * n) {
    int x;
    while (v[cur].used && cur < 2 * n) {
      cur++;
    }
    if (cur >= 2 * n) break;
    cout << v[cur].place + 1 << endl;
    cur++;
    while (v[cur].used && cur < 2 * n) {
      cur++;
    }
    if (cur >= 2 * n) break;
    cin >> x;
    v[places[x - 1]].used = true;
  }
  return 0;
}
