#include <bits/stdc++.h>
using namespace std;
int n, m, p[20005], d, vis[20005];
vector<pair<int, int> > v, rem;
int turn;
void solve() {
  cin >> n >> m;
  for (int i = 1; i < 2 * n + 1; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < m; i++) {
    int first, second;
    cin >> first >> second;
    if (p[first] < p[second]) swap(first, second);
    v.push_back({first, second});
    vis[first] = 1;
    vis[second] = 1;
  }
  for (int i = 1; i < 2 * n + 1; i++)
    if (!vis[i]) rem.push_back({p[i], i});
  sort((rem).begin(), (rem).end());
  reverse((rem).begin(), (rem).end());
  cin >> turn;
  if (turn == 1) {
    int pos = 0, cur = 0;
    for (int i = 0; i < n; i++) {
      if (pos < (int)v.size()) {
        cout << v[pos].first << endl;
        cin >> d;
        assert(d == v[pos].second);
        pos++;
      } else {
        while (vis[rem[cur].second]) cur++;
        cout << rem[cur].second << endl;
        vis[rem[cur].second] = 1;
        cur++;
        cin >> d;
        vis[d] = 1;
      }
    }
  } else {
    memset(vis, 0, sizeof vis);
    for (int _ = 0; _ < n; _++) {
      cin >> d;
      vis[d] = 1;
      bool done = 0;
      for (auto i : v) {
        if (i.first == d or i.second == d) {
          if (vis[i.first + i.second - d]) break;
          cout << i.first + i.second - d << endl;
          vis[i.first + i.second - d] = 1;
          done = 1;
          break;
        }
      }
      if (done) continue;
      for (auto i : v) {
        if (vis[i.first] == 0) {
          cout << i.first << endl;
          vis[i.first] = 1;
          done = 1;
          break;
        }
      }
      if (done) continue;
      int pos = -1;
      for (int j = 1; j < 2 * n + 1; j++) {
        if (vis[j] == 0) {
          if (pos == -1 or p[pos] < p[j]) pos = j;
        }
      }
      cout << pos << endl;
      vis[pos] = 1;
    }
    cin >> d;
  }
}
signed main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
