#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int powmod(int base, int exp, int mod) {
  int res = 1LL;
  while (exp > 0) {
    if (exp & 1LL) res = (res * base) % mod;
    exp /= 2LL;
    base = (base * base) % mod;
  }
  return res % mod;
}
int arr[2009];
int alph[2009];
int main() {
  int n, m;
  cin >> n >> m;
  int a[2 * n + 1];
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
  }
  int x, y;
  vector<pair<int, int> > v;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    arr[x] = y;
    arr[y] = x;
    v.push_back({x, y});
  }
  int t;
  cin >> t;
  int val = 0;
  if (t == 1) {
    int var;
    int count = v.size() - 1;
    for (int i = count; i >= 0; i--) {
      int some1 = v[i].first;
      int some2 = v[i].second;
      if (a[some1] > a[some2]) {
        cout << some1 << endl;
        cout.flush();
      } else {
        cout << some2 << endl;
        cout.flush();
      }
      cin >> var;
      alph[some1] = 1;
      alph[some2] = 1;
      val++;
    }
    while (val != n) {
      int maxi = -1, ans;
      for (int i = 1; i <= 2 * n; i++) {
        if (alph[i] == 0 && a[i] > maxi) {
          ans = i;
          maxi = a[i];
        }
      }
      cout << ans << endl;
      cout.flush();
      cin >> var;
      val++;
      alph[ans] = 1;
      alph[var] = 1;
    }
  } else {
    while (val != n) {
      int var;
      cin >> var;
      if (arr[var] != 0) {
        cout << arr[var] << endl;
        cout.flush();
        alph[var] = 1;
        alph[arr[var]] = 1;
        val++;
      } else {
        alph[var] = 1;
        for (int i = 0; i < v.size(); i++) {
          int some1 = v[i].first;
          int some2 = v[i].second;
          if (alph[some1] || alph[some2]) {
            continue;
          } else {
            if (a[some2] > a[some1]) {
              cout << some2 << endl;
              cout.flush();
            } else {
              cout << some1 << endl;
              cout.flush();
            }
            cin >> var;
            val++;
            alph[some2] = 1;
            alph[some1] = 1;
          }
        }
        int maxi = -1, ans;
        for (int i = 1; i <= 2 * n; i++) {
          if (alph[i] == 0 && a[i] > maxi) {
            ans = i;
            maxi = a[i];
          }
        }
        alph[ans] = 1;
        cout << ans << endl;
        cout.flush();
        val++;
      }
    }
  }
}
