#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10, mod = 1000 * 1000 * 1000 + 7;
int mat[N];
bool mark[N];
int a[N], b[N];
void go(int x) {
  int y;
  cout << x << endl;
  cin >> y;
  mark[x] = mark[y] = 1;
}
bool cmp(int x, int y) { return a[x] > a[y]; }
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<pair<int, int>> v;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) cin >> a[i], b[i - 1] = i;
  sort(b, b + 2 * n, cmp);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] < a[y]) swap(x, y);
    v.push_back({x, y});
  }
  int t;
  cin >> t;
  if (t == 1) {
    for (auto u : v) go(u.first);
    for (int i = 0; i < n - m; i++) {
      for (int j = 0; j < 2 * n; j++) {
        if (!mark[b[j]]) {
          go(b[j]);
          break;
        }
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      bool f = 0;
      mark[x] = 1;
      for (auto u : v) {
        if (u.first == x && !mark[u.second]) {
          cout << u.second << endl;
          mark[u.second] = 1;
          f = 1;
        }
        if (u.second == x && !mark[u.first]) {
          cout << u.first << endl;
          mark[u.first] = 1;
          f = 1;
        }
      }
      if (f) continue;
      for (auto u : v) {
        if (!mark[u.first]) {
          f = 1;
          cout << u.first << endl;
          mark[u.first] = 1;
          break;
        }
      }
      if (f) continue;
      for (int j = 0; j < 2 * n; j++) {
        if (!mark[b[j]]) {
          cout << b[j] << endl;
          mark[b[j]] = 1;
          break;
        }
      }
    }
  }
}
