#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:667177216")
using namespace std;
const long long MOD = 9901;
const long long MAXN = 100000 + 100;
void solve_smart(long long n, long long m) {
  long long ans = 0;
  if (n <= m) {
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= n; ++j) {
        if ((i * i + j * j) % m == 0) {
          ans++;
        }
      }
    }
  } else {
    for (long long i = 1; i <= m; i++) {
      for (long long j = 1; j <= m; ++j) {
        if ((i * i + j * j) % m == 0) {
          long long x = (n - i) / m + 1;
          long long y = (n - j) / m + 1;
          ans += x * y;
        }
      }
    }
  }
  cout << ans << endl;
}
void solve_stupid(long long n, long long m) {
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; ++j) {
      if ((i * i + j * j) % m == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(2 * n + 1);
  for (int(i) = 1; (i) < 2 * n + 1; (i)++) cin >> p[i].first;
  for (int(i) = 1; (i) < 2 * n + 1; (i)++) p[i].second = i;
  vector<pair<int, int>> b(m);
  for (int(i) = 0; (i) < m; (i)++) cin >> b[i].first >> b[i].second;
  sort((p).begin(), (p).end());
  int opp[2001];
  memset(opp, -1, sizeof(opp));
  for (int(i) = 0; (i) < m; (i)++) {
    opp[b[i].first] = b[i].second;
    opp[b[i].second] = b[i].first;
  }
  vector<char> played(2 * n + 1, 0);
  int buf;
  int start;
  cin >> start;
  if (start == 1) {
    for (int i = 2 * n; i >= 1; --i) {
      auto cur = p[i];
      int power = cur.first;
      int num = cur.second;
      if (played[num]) continue;
      if (opp[num] == -1) continue;
      cout << num << endl << flush;
      cin >> buf;
      played[num] = 1;
      played[buf] = 1;
    }
    for (int i = 2 * n; i >= 1; --i) {
      auto cur = p[i];
      int power = cur.first;
      int num = cur.second;
      if (played[num]) continue;
      cout << num << endl << flush;
      cin >> buf;
      played[num] = played[buf] = 1;
    }
  } else {
    int count = 0;
    while (count < 2 * n) {
      cin >> buf;
      count++;
      played[buf] = 1;
      if (opp[buf] == -1) break;
      if (count == 2 * n) return 0;
      cout << opp[buf] << endl << flush;
      count++;
      played[opp[buf]] = 1;
    }
    if (count == 2 * n) return 0;
    for (int i = 2 * n; i >= 1; --i) {
      auto cur = p[i];
      int power = cur.first;
      int num = cur.second;
      if (played[num]) continue;
      if (opp[num] == -1) continue;
      cout << num << endl << flush;
      count++;
      if (count == 2 * n) return 0;
      cin >> buf;
      count++;
      played[num] = 1;
      played[buf] = 1;
    }
    for (int i = 2 * n; i >= 1; --i) {
      auto cur = p[i];
      int power = cur.first;
      int num = cur.second;
      if (played[num]) continue;
      cout << num << endl << flush;
      count++;
      if (count == 2 * n) return 0;
      cin >> buf;
      count++;
      played[num] = played[buf] = 1;
    }
  }
  return 0;
}
