#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e3 + 100;
bool used[N];
int power[N], adj[N];
void printflush(int t) {
  printf("%d\n", t);
  fflush(stdout);
}
int checkans() {
  int t;
  scanf("%d", &t);
  if (t == -1) {
    exit(0);
  }
  used[t] = true;
  return t;
}
int main() {
  int n, m, a, b;
  scanf("%d %d", &n, &m);
  int mx = 0;
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &power[i]);
    mx = max(mx, power[i]);
  }
  priority_queue<pair<int, int> > pq;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    adj[a] = b;
    adj[b] = a;
    if (power[a] < power[b]) {
      swap(a, b);
    }
    pq.push({power[a] + mx, a});
  }
  for (int i = 1; i <= 2 * n; i++) {
    if (!adj[i]) {
      pq.push({power[i], i});
    }
  }
  int t;
  scanf("%d", &t);
  if (t == 1) {
    for (int i = 0; i < n; i++) {
      while (used[pq.top().second]) {
        pq.pop();
      }
      pair<int, int> x = pq.top();
      pq.pop();
      used[x.second] = true;
      printflush(x.second);
      checkans();
    }
  } else {
    for (int i = 0; i < n; i++) {
      t = checkans();
      if (adj[t] && !used[adj[t]]) {
        used[adj[t]] = true;
        printflush(adj[t]);
        continue;
      }
      while (used[pq.top().second]) {
        pq.pop();
      }
      pair<int, int> x = pq.top();
      pq.pop();
      used[x.second] = true;
      printflush(x.second);
    }
  }
  return 0;
}
