#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 3;
int heroPower[N];
map<int, int> againstHero;
set<pair<int, int> > heroSet;
void play(int);
void playOptimally() {
  if (againstHero.size()) {
    int a = (*againstHero.begin()).first, b = (*againstHero.begin()).second;
    if (heroPower[a] > heroPower[b]) {
      cout << a << endl << endl;
    } else {
      cout << b << endl << endl;
    }
    againstHero.erase(a);
    againstHero.erase(b);
    heroSet.erase({-heroPower[a], a});
    heroSet.erase({-heroPower[b], b});
    cin >> a;
    play(1);
  } else {
    int bestHero = (*heroSet.begin()).second;
    cout << bestHero << endl << endl;
    heroSet.erase(heroSet.begin());
    play(2);
  }
}
void play(int turn) {
  if (heroSet.size() == 0) return;
  if (turn == 1) {
    playOptimally();
  } else {
    int p;
    cin >> p;
    heroSet.erase({-heroPower[p], p});
    if (againstHero.find(p) != againstHero.end()) {
      int against = againstHero[p];
      cout << against << endl << endl;
      againstHero.erase(p);
      againstHero.erase(against);
      heroSet.erase({-heroPower[against], against});
      play(2);
    } else {
      play(1);
    }
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= 2 * n; ++i) {
    int xi;
    scanf("%d", &xi);
    heroPower[i] = xi;
    heroSet.insert({-xi, i});
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    againstHero[a] = b;
    againstHero[b] = a;
  }
  int t;
  scanf("%d", &t);
  play(t);
  return 0;
}
