#include <bits/stdc++.h>
const long long LLINF = (1ll << 63) - 1;
const int INF = (1 << 31) - 1;
const long double PI = 3.141592653589793;
const long double EPS = 1e-15;
const unsigned long long MOD = (1e9) + 7;
const unsigned long long MOD2 = 16714589;
const int ENGLISH_ALPHABET_SIZE = 26;
const int N = 1e5;
const int M = 1e9 + 10;
using namespace std;
int m, n, t;
vector<int> pairs, used;
vector<pair<int, int>> powers;
set<int> first_move;
bool make_move() {
  int x;
  cin >> x;
  if (x == -1) return false;
  x--;
  used[x] = 1;
  first_move.erase(x);
  if (pairs[x] >= 0 && !used[pairs[x]]) {
    cout << pairs[x] + 1 << endl;
    used[pairs[x]] = 1;
    first_move.erase(pairs[x]);
    return true;
  }
  if (!first_move.empty()) {
    auto e = first_move.begin();
    cout << *e + 1 << endl;
    used[*e] = 1;
    first_move.erase(e);
    return true;
  }
  for (int i = 0; i < 2 * n; ++i) {
    if (!used[powers[i].second]) {
      cout << powers[i].second + 1 << endl;
      used[powers[i].second] = 1;
      break;
    }
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  pairs.resize(2 * n, -1);
  powers.resize(2 * n);
  used.resize(2 * n, 0);
  for (int i = 0, x; i < 2 * n; ++i) {
    cin >> x;
    powers[i] = {x, i};
  }
  for (int i = 0, a, b; i < m; ++i) {
    cin >> a >> b;
    a--, b--;
    if (powers[a].first > powers[b].first) {
      first_move.insert(a);
    } else
      first_move.insert(b);
    pairs[a] = b;
    pairs[b] = a;
  }
  cin >> t;
  sort((powers).begin(), (powers).end(), greater<pair<int, int>>());
  int mv_cnt = 0;
  if (t == 1) {
    if (first_move.empty()) {
      cout << powers[0].second + 1 << endl;
      used[powers[0].second] = 1;
    } else {
      auto e = first_move.begin();
      cout << *e + 1 << endl;
      used[*e] = 1;
      first_move.erase(e);
    }
    cout.flush();
    mv_cnt++;
  }
  while (mv_cnt < n) {
    if (!make_move()) break;
    cout.flush();
    mv_cnt++;
  }
  return 0;
}
