#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3000;
pair<int, int> p[MAX_N];
int indexOf[MAX_N];
int other[MAX_N];
pair<int, pair<int, int> > otherPairs[MAX_N];
int used[MAX_N] = {0};
int main() {
  int n, m;
  cin >> n >> m;
  int tot = 2 * n;
  for (int i = 0; i < 2 * n; ++i) {
    cin >> p[i].first;
    p[i].second = i + 1;
  }
  sort(p, p + tot);
  reverse(p, p + tot);
  for (int i = 0; i < tot; ++i) {
    indexOf[p[i].second] = i;
  }
  fill(begin(other), end(other), -1);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    other[x] = y;
    other[y] = x;
    int px = p[indexOf[x]].first;
    int py = p[indexOf[y]].first;
    otherPairs[i] = make_pair(max(px, py), make_pair(x, y));
  }
  sort(otherPairs, otherPairs + m);
  reverse(otherPairs, otherPairs + m);
  int t;
  cin >> t;
  t--;
  int prevJudge = -1;
  for (int i = 0; i < tot; ++i, t ^= 1) {
    if (t == 0) {
      int x = -1;
      if (prevJudge != -1 && other[prevJudge] != -1 &&
          !used[other[prevJudge]]) {
        x = other[prevJudge];
      } else {
        for (int j = 0; j < m; ++j) {
          int first = otherPairs[j].second.first;
          int second = otherPairs[j].second.second;
          if (!used[first]) {
            int pf = p[indexOf[first]].first;
            int ps = p[indexOf[second]].first;
            x = pf > ps ? first : second;
            break;
          }
        }
        if (x == -1) {
          for (int i = 0; i < tot; ++i) {
            if (!used[p[i].second]) {
              x = p[i].second;
              break;
            }
          }
        }
      }
      used[x] = true;
      cout << x << endl;
      cout << flush;
    } else {
      int x;
      cin >> x;
      prevJudge = x;
      used[x] = true;
    }
  }
  return 0;
}
