#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> p(2 * n), bad(2 * n, -1);
  for (int i = 0; i < 2 * n; ++i) {
    cin >> p[i];
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    bad[u - 1] = v - 1;
    bad[v - 1] = u - 1;
  }
  int t;
  cin >> t;
  vector<bool> used(2 * n);
  if (t == 1) {
    for (int i = 0; i < n; ++i) {
      pair<int, int> max_pair(-1, -1), maxx(-1, -1);
      for (int j = 0; j < 2 * n; ++j) {
        if (!used[j]) {
          if (bad[j] != -1) {
            max_pair = max(max_pair, {p[j], j + 1});
          }
          maxx = max(maxx, {p[j], j + 1});
        }
      }
      if (max_pair.first != -1) {
        cout << max_pair.second << endl;
        used[max_pair.second - 1] = true;
      } else {
        cout << maxx.second << endl;
        used[maxx.second - 1] = true;
      }
      int get;
      cin >> get;
      used[get - 1] = true;
    }
  } else {
    bool gg = false;
    for (int i = 0; i < n; ++i) {
      int get;
      cin >> get;
      gg |= bad[get - 1] == -1;
      used[get - 1] = true;
      if (gg) {
        pair<int, int> max_pair(-1, -1), maxx(-1, -1);
        for (int j = 0; j < 2 * n; ++j) {
          if (!used[j]) {
            if (bad[j] != -1) {
              max_pair = max(max_pair, {p[j], j + 1});
            }
            maxx = max(maxx, {p[j], j + 1});
          }
        }
        if (max_pair.first != -1) {
          cout << max_pair.second << endl;
          used[max_pair.second - 1] = true;
        } else {
          cout << maxx.second << endl;
          used[maxx.second - 1] = true;
        }
      } else {
        cout << bad[get - 1] + 1 << endl;
        used[bad[get - 1]] = true;
      }
    }
  }
  return 0;
}
