#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 2 * 1e3 + 1;
int opp[N] = {}, arr[N], lst[N];
bool usd[N] = {};
vector<pair<int, int> > sp;
void solve1() {
  for (auto i : sp) {
    cout << i.first << "\n";
    cout.flush();
    int x;
    cin >> x;
    usd[i.first] = usd[i.second] = 1;
  }
  int i1 = 1;
  for (int i = m; i < n; ++i) {
    while (usd[lst[i1]]) ++i1;
    int x = lst[i1];
    cout << x << "\n";
    cout.flush();
    usd[x] = 1;
    cin >> x;
    usd[x] = 1;
  }
  return;
}
void solve2() {
  int my = 0, his = 0;
  while (my < n) {
    int x;
    cin >> x;
    usd[x] = 1;
    ++his;
    if (!opp[x]) break;
    x = opp[x];
    cout << x << "\n";
    cout.flush();
    usd[x] = 1;
    ++my;
  }
  if (my == n) return;
  int i1 = 0;
  while (my < n) {
    while (i1 < m && usd[sp[i1].first]) ++i1;
    if (i1 == m) break;
    pair<int, int> x = sp[i1];
    cout << x.first << "\n";
    cout.flush();
    ++my;
    int xx;
    cin >> xx;
    ++his;
    usd[x.first] = usd[x.second] = 1;
  }
  if (my == n) return;
  i1 = 1;
  while (my < n) {
    while (usd[lst[i1]]) ++i1;
    cout << lst[i1] << "\n";
    cout.flush();
    usd[lst[i1]] = 1;
    ++my;
    if (my == n) break;
    int x;
    cin >> x;
    usd[x] = 1;
  }
  return;
}
bool comp(pair<int, int> p1, pair<int, int> p2) {
  return arr[p1.first] > arr[p2.first];
}
bool comp2(int p1, int p2) { return arr[p1] > arr[p2]; }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; ++i) {
    cin >> arr[i];
    lst[i] = i;
  }
  sp.resize(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (arr[b] > arr[a]) swap(a, b);
    sp[i] = {a, b};
    opp[a] = b;
    opp[b] = a;
  }
  sort(sp.begin(), sp.end(), comp);
  sort(lst + 1, lst + 2 * n + 1, comp2);
  int t;
  cin >> t;
  if (t == 1)
    solve1();
  else
    solve2();
  return 0;
}
