#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3;
bool taken[MAXN];
long long ppair[MAXN];
long long force[MAXN];
long long n, m;
void step() {
  long long id = -1;
  long long p = -1;
  for (long long i = 0; i < 2 * n; i++) {
    if (!taken[i]) {
      if (id == -1 || force[id] <= force[i]) {
        id = i;
      }
      if (ppair[i] != -1) {
        p = i;
      }
    }
  }
  if (p != -1) {
    if (force[p] < force[ppair[p]]) p = ppair[p];
    taken[p] = true;
    cout << p + 1 << endl;
  } else {
    taken[id] = true;
    cout << id + 1 << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 0; i < 2 * n; i++) {
    cin >> force[i];
    ppair[i] = -1;
  }
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    ppair[a] = b;
    ppair[b] = a;
  }
  long long t;
  cin >> t;
  if (t == 1) {
    for (long long i = 0; i < n; i++) {
      step();
      long long x;
      cin >> x;
      if (x == -1) return 0;
      x--;
      taken[x] = true;
    }
  } else {
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      if (x == -1) return 0;
      x--;
      taken[x] = true;
      if (ppair[x] != -1 && !taken[ppair[x]]) {
        cout << ppair[x] + 1 << endl;
        taken[x] = taken[ppair[x]] = true;
      } else {
        step();
      }
    }
  }
  return 0;
}
