#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  long long x = 0, n = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar()) n = (c == '-');
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return n ? -x : x;
}
const int N = 2e3 + 5;
int n, m, n2;
pair<int, int> a[N];
int A = 1;
int now[N];
int p[N];
int d[N];
int use2;
vector<pair<int, int> > pr;
int Pr;
void USE1(int x) {
  d[now[x]] = 1;
  cout << x << endl;
}
void USE2() {
  cin >> use2;
  d[now[use2]] = 1;
}
void NOR() {
  while (Pr <= (int)pr.size() - 1) {
    pair<int, int> x = pr[Pr];
    if (d[now[x.first]]) {
      Pr++;
      continue;
    }
    USE1(x.first);
    Pr++;
    return;
  }
  while (d[A]) A++;
  USE1(a[A].second);
}
int main() {
  cin >> n >> m;
  n2 = n * 2;
  for (int i = 1; i <= n2; i++) cin >> a[i].first, a[i].second = i;
  for (int drfds = 1; drfds <= m; drfds++) {
    int x, y;
    cin >> x >> y;
    p[x] = y, p[y] = x;
    if (a[x].first < a[y].first) swap(x, y);
    pr.push_back({x, y});
  }
  sort(a + 1, a + n2 + 1, greater<pair<int, int> >());
  for (int i = 1; i <= n2; i++) now[a[i].second] = i;
  int t = in();
  for (int asdoe = 1; asdoe <= n; asdoe++) {
    if (t == 1) {
      NOR();
      USE2();
    } else {
      USE2();
      int P = p[use2];
      if (P && !d[now[P]])
        USE1(P);
      else
        NOR();
    }
    cout << endl;
  }
}
