#include <bits/stdc++.h>
using namespace std;
long long n, m, p[2006], val, t;
set<pair<long long, long long>, greater<pair<long long, long long> > > s;
set<pair<long long, long long>, greater<pair<long long, long long> > > a;
map<long long, long long> l;
long long play(long long val) {
  long long move;
  if (val != 0) {
    s.erase({p[val], val});
    if (l[val]) {
      move = l[val];
      s.erase({p[move], move});
      l.erase(move);
      l.erase(val);
      if (p[move] > p[val])
        a.erase({move, val});
      else
        a.erase({val, move});
      return move;
    }
  }
  if (!a.empty()) {
    move = a.begin()->first;
    a.erase({move, l[move]});
    s.erase({p[move], move});
    l.erase(l[move]);
    l.erase(move);
    return move;
  } else {
    move = s.begin()->second;
    s.erase({p[move], move});
    return move;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long TESTS = 1;
  while (TESTS--) {
    cin >> n >> m;
    for (long long i = 1; i < 2 * n + 1; i++) {
      cin >> p[i];
      s.insert({p[i], i});
    }
    for (long long i = 0; i < m; i++) {
      long long u, v;
      cin >> u >> v;
      l[u] = v;
      l[v] = u;
      if (p[u] > p[v])
        a.insert({u, v});
      else
        a.insert({v, u});
    }
    cin >> t;
    if (t == 1) {
      for (long long i = 0; i < n; i++) {
        cout << play(val) << '\n';
        cout.flush();
        cin >> val;
        if (val == -1) break;
      }
    }
    if (t == 2) {
      for (long long i = 0; i < n; i++) {
        cin >> val;
        if (val == -1) break;
        cout << play(val) << '\n';
        cout.flush();
      }
    }
  }
  return 0;
}
