#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long int rand(long long int x, long long int y) {
  ++y;
  return (rng() % (y - x)) + x;
}
long long int n, m, aa, t, taken[10006], bounded[10006], took;
vector<pair<long long int, long long int> > hero;
pair<long long int, long long int> A[10006];
int main() {
  cin >> n >> m;
  for (long long int i = 1; i <= 2 * n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  memset((bounded), -1, sizeof((bounded)));
  ;
  for (long long int i = 0; i < m; i++) {
    pair<long long int, long long int> hi;
    cin >> hi.first >> hi.second;
    hero.push_back(hi);
    if (A[hero[i].first].first < A[hero[i].second].first)
      swap(hero[i].first, hero[i].second);
    bounded[hero[i].first] = hero[i].second,
    bounded[hero[i].second] = hero[i].first;
  }
  cin >> t;
  if (t == 1) {
    while (!hero.empty()) {
      cout << hero.back().first << '\n';
      cout.flush();
      long long int t;
      cin >> t;
      assert(t == hero.back().second);
      taken[hero.back().first] = taken[t] = 1;
      hero.pop_back();
    }
    sort(A + 1, A + (2 * n) + 1,
         greater<pair<long long int, long long int> >());
    for (long long int i = 1; i <= 2 * n; i++) {
      long long int ind = A[i].second;
      if (!taken[ind]) {
        cout << ind << "\n";
        cout.flush();
        long long int t;
        cin >> t;
        taken[ind] = taken[t] = 1;
      }
    }
  } else {
    while (took < 2 * n) {
      long long int t;
      cin >> t;
      taken[t] = 1;
      took++;
      if (bounded[t] == -1 || took >= 2 * n) break;
      cout << bounded[t] << "\n";
      cout.flush();
      took++;
      taken[bounded[t]] = 1;
    }
    while (!hero.empty()) {
      if (taken[hero.back().first] || taken[hero.back().second]) {
        hero.pop_back();
        continue;
      }
      took += 2;
      cout << hero.back().first << '\n';
      cout.flush();
      long long int t;
      cin >> t;
      assert(t == hero.back().second);
      taken[hero.back().first] = taken[t] = 1;
      hero.pop_back();
    }
    sort(A + 1, A + (2 * n) + 1,
         greater<pair<long long int, long long int> >());
    for (long long int i = 1; i <= 2 * n; i++) {
      long long int ind = A[i].second;
      if (!taken[ind]) {
        cout << ind << "\n";
        cout.flush();
        took++;
        if (took >= 2 * n) break;
        assert(took <= 2 * n);
        long long int t;
        cin >> t;
        taken[ind] = taken[t] = 1;
        took++;
      }
    }
  }
}
