#include <bits/stdc++.h>
using namespace std;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void dumpc(Iter begin, Iter end) {
  if (true) {
    for (; begin != end; ++begin) {
      cerr << *begin << ',';
    }
    cerr << endl;
  }
}
const int MAX_N = 2e3 + 1;
int P[MAX_N];
int Q[MAX_N];
int viz[MAX_N];
int N, M, T;
void choose(int x) {
  viz[x] = 1;
  cout << x << endl;
}
int xread() {
  int i;
  cin >> i;
  if (i == -1) exit(0);
  assert(!viz[i]);
  viz[i] = 1;
  return i;
}
void solve() {
  memset(viz, 0, sizeof(viz));
  T -= 1;
  int t = 0, force = -1;
  while (t < 2 * N) {
    if (t % 2 == T) {
      if (force != -1) {
        choose(force);
        force = -1;
      } else {
        vector<pair<int, int>> ps;
        for (int i = (1); i <= (2 * N); ++i)
          if (!viz[i]) ps.emplace_back((Q[i] > 0 ? 1e4 : 0) + P[i], i);
        sort((ps).begin(), (ps).end());
        reverse((ps).begin(), (ps).end());
        int v = ps.front().first;
        vector<pair<int, int>> qs;
        for (int i = 0; i < (int((ps).size())); ++i)
          if (ps[i].first == v) {
            int j = ps[i].second;
            int part = 0;
            if (Q[j] > 0) part = P[Q[j]];
            qs.emplace_back(part, j);
          }
        sort((qs).begin(), (qs).end());
        auto it = lower_bound((qs).begin(), (qs).end(), make_pair(1, -1));
        if (it == qs.end()) it = qs.begin();
        choose(it->second);
      }
    } else {
      int x = xread();
      if (Q[x] > 0 && !viz[Q[x]]) force = Q[x];
    }
    ++t;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 0; i < (2 * N); ++i) cin >> P[i + 1];
  for (int i = 0; i < (M); ++i) {
    int a, b;
    cin >> a >> b;
    Q[a] = b;
    Q[b] = a;
  }
  cin >> T;
  solve();
  return 0;
}
