#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 2010;
int n, m;
int p[N];
int pegou[N];
int pega_maior() {
  int resp = 0;
  int idx = -1;
  for (int i = 1; i <= 2 * n; i++) {
    if (pegou[i]) continue;
    if (p[i] > resp) resp = p[i], idx = i;
  }
  return idx;
}
int pega[N];
int pega_pega() {
  for (int i = 1; i <= 2 * n; i++) {
    if (pegou[i] or !pega[i]) continue;
    int u = i;
    int v = pega[i];
    if (p[u] > p[v]) return u;
    return v;
  }
  return -1;
}
void comecei() {
  while (true) {
    int x = pega_pega();
    if (x != -1) {
      pegou[x] = 1;
    } else {
      break;
    }
    cout << x << endl;
    cin >> x;
    pegou[x] = 1;
  }
  while (true) {
    int x = pega_maior();
    if (x != -1) {
      pegou[x] = 1;
    } else {
      break;
    }
    cout << x << endl;
    cin >> x;
    pegou[x] = 1;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) cin >> p[i];
  vector<pair<int, int> > dupla;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    pega[u] = v;
    pega[v] = u;
  }
  int t;
  cin >> t;
  if (t == 1) {
    comecei();
  } else {
    int iter = n;
    while (iter > 0) {
      int x;
      cin >> x;
      pegou[x] = 1;
      if (pega[x]) {
        cout << pega[x] << endl;
        pegou[pega[x]] = 1;
      } else {
        comecei();
        break;
      }
      iter--;
    }
  }
  return 0;
}
