#include <bits/stdc++.h>
using namespace std;
int n, m;
set<pair<int, int> > s;
int x[20005], y[20005];
int a[20005];
int t;
int top;
int input;
void out() {
  for (int i = 0; i < m; i++) {
    if (x[i] == input) {
      if (s.find(pair<int, int>(a[y[i]], y[i])) == s.end()) continue;
      printf("%d\n", y[i]);
      fflush(stdout);
      s.erase(pair<int, int>(a[y[i]], y[i]));
      return;
    } else if (y[i] == input) {
      if (s.find(pair<int, int>(a[x[i]], x[i])) == s.end()) continue;
      printf("%d\n", x[i]);
      fflush(stdout);
      s.erase(pair<int, int>(a[x[i]], x[i]));
      return;
    }
  }
  while (top < m) {
    int now;
    if (a[x[top]] > a[y[top]])
      now = x[top];
    else
      now = y[top];
    if (s.find(pair<int, int>(a[now], now)) == s.end()) {
      top++;
      continue;
    }
    printf("%d\n", now);
    fflush(stdout);
    s.erase(pair<int, int>(a[now], now));
    top++;
    return;
  }
  auto iter = s.end();
  iter--;
  printf("%d\n", iter->second);
  fflush(stdout);
  s.erase(iter);
}
void in() {
  int now;
  scanf("%d", &now);
  s.erase(pair<int, int>(a[now], now));
  input = now;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &a[i]);
    s.insert(pair<int, int>(a[i], i));
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x[i], &y[i]);
  }
  top = 0;
  input = 0;
  cin >> t;
  if (t == 1) out();
  while (!s.empty()) {
    in();
    if (s.empty()) break;
    out();
  }
  return 0;
}
