#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
  if (n2 == 0) return n1;
  if (n1 % n2 == 0) return n2;
  return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
  if (exponent < 0) exponent += 1000000007LL - 1;
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % 1000000007LL;
    base = (base * base) % 1000000007LL;
    exponent /= 2;
  }
  return ans;
}
set<pair<int, int> > s;
int a[1000005], b[1000005], p[1000005];
int N[1000005];
set<int> val;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) {
    int x;
    cin >> x;
    p[i] = x;
    s.insert(make_pair(-x, i));
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    if (p[a[i]] < p[b[i]]) swap(a[i], b[i]);
    N[a[i]] = b[i];
    N[b[i]] = a[i];
    val.insert(i);
  }
  int t;
  cin >> t;
  int pre = 0;
  for (int i = 1; i <= 2 * n; i++) {
    if ((i % 2) == (t % 2)) {
      bool flag = false;
      for (int i : val) {
        if (a[i] == pre) {
          val.erase(i);
          flag = true;
          break;
        } else if (b[i] == pre) {
          val.erase(i);
          flag = true;
          break;
        }
      }
      if (flag) {
        int ans = N[pre];
        s.erase(make_pair(-p[ans], ans));
        cout << ans << endl;
      } else {
        if ((val.size())) {
          int x = *val.begin();
          val.erase(val.begin());
          s.erase(make_pair(-p[a[x]], a[x]));
          cout << a[x] << endl;
        } else {
          auto x = *s.begin();
          s.erase(s.begin());
          cout << x.second << endl;
        }
      }
    } else {
      cin >> pre;
      s.erase(make_pair(-p[pre], pre));
    }
  }
}
