#include <bits/stdc++.h>
using namespace std;
int a[2005];
int complement[2005];
bool avl[2005];
vector<int> myvec;
struct Hero {
  int idx;
  int power;
  Hero(int idx, int power) : idx(idx), power(power) {}
};
struct Compare_Hero {
  bool operator()(Hero const& a, Hero const& b) { return (a.power < b.power); }
};
priority_queue<Hero, vector<Hero>, Compare_Hero> HeroQueue;
int main() {
  int n, m, p, q, turn;
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
    avl[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> p >> q;
    if (a[p] >= a[q]) {
      myvec.push_back(p);
    } else
      myvec.push_back(q);
    complement[p] = q;
    complement[q] = p;
  }
  cin >> turn;
  if (turn == 1) {
    for (int i = 1; i <= m; i++) {
      cout << myvec[i - 1] << endl << flush;
      cin >> p;
      avl[myvec[i - 1]] = 0;
      avl[p] = 0;
    }
    for (int i = 1; i <= 2 * n; i++) {
      if (avl[i]) {
        HeroQueue.push(Hero(i, a[i]));
      }
    }
    for (int i = 1; i <= (n - m); i++) {
      int nx = HeroQueue.top().idx;
      while (!avl[nx]) {
        HeroQueue.pop();
        nx = HeroQueue.top().idx;
      }
      cout << nx << endl << flush;
      cin >> p;
      avl[p] = avl[nx] = 0;
    }
  } else {
    for (int i = 1; i <= 2 * n; i++) {
      HeroQueue.push(Hero(i, a[i]));
    }
    for (int i = 1; i <= n; i++) {
      cin >> p;
      avl[p] = 0;
      if (complement[p] && avl[complement[p]]) {
        cout << complement[p] << endl << flush;
        avl[complement[p]] = 0;
        m--;
        continue;
      } else if (m) {
        int it = 0;
        while (m) {
          m--;
          while (!avl[myvec[it]]) it++;
          cout << myvec[it] << endl << flush;
          avl[myvec[it]] = avl[p] = 0;
          i++;
          if (m)
            cin >> p;
          else
            i--;
        }
        continue;
      }
      int nx = HeroQueue.top().idx;
      while (!avl[nx]) {
        HeroQueue.pop();
        nx = HeroQueue.top().idx;
      }
      cout << nx << endl << flush;
      avl[nx] = 0;
    }
  }
  return 0;
}
