#include <bits/stdc++.h>
using namespace std;
int N, M;
int P[2001];
bool marked[2001];
int X[2001], Y[2001];
map<int, int> mp;
int main() {
  cin >> N >> M;
  N *= 2;
  for (int i = 1; i <= N; i++) cin >> P[i];
  for (int i = 0; i < M; i++) {
    cin >> X[i] >> Y[i];
    mp[X[i]] = Y[i];
    mp[Y[i]] = X[i];
  }
  int T;
  cin >> T;
  if (T == 1) {
    for (int i = 0; i < M; i++) {
      int trash;
      if (P[X[i]] > P[Y[i]]) {
        cout << X[i] << '\n';
        cout << flush;
      } else {
        cout << Y[i] << '\n';
        cout << flush;
      }
      cin >> trash;
      marked[X[i]] = true;
      marked[Y[i]] = true;
    }
    vector<pair<int, int>> v;
    for (int i = 1; i <= N; i++)
      if (!marked[i]) v.push_back({-P[i], i});
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      if (!marked[v[i].second]) {
        cout << v[i].second << '\n';
        cout << flush;
        int temp;
        cin >> temp;
        marked[temp] = true;
      }
    }
  } else {
    int moves = 0;
    for (int i = 0; i < N; i++) {
      int move;
      cin >> move;
      marked[move] = true;
      if (mp.count(move) == 1) {
        cout << mp[move] << '\n';
        cout << flush;
        moves++;
        if (moves == N / 2) return 0;
        marked[mp[move]] = true;
        continue;
      } else {
        for (int i = 0; i < M; i++) {
          int trash;
          if (!marked[X[i]]) {
            if (P[X[i]] > P[Y[i]]) {
              cout << X[i] << '\n';
              cout << flush;
            } else {
              cout << Y[i] << '\n';
              cout << flush;
            }
            moves++;
            if (moves == N / 2) return 0;
            cin >> trash;
            marked[X[i]] = true;
            marked[Y[i]] = true;
          }
        }
        vector<pair<int, int>> v;
        for (int i = 1; i <= N; i++)
          if (!marked[i]) v.push_back({-P[i], i});
        sort(v.begin(), v.end());
        for (int i = 0; i < v.size(); i++) {
          if (!marked[v[i].second]) {
            cout << v[i].second << '\n';
            cout << flush;
            moves++;
            if (moves == N / 2) return 0;
            int temp;
            cin >> temp;
            marked[temp] = true;
          }
        }
        return 0;
      }
    }
  }
  return 0;
}
