#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 1e6 + 10;
int p[SIZE], pp[SIZE];
bool u[SIZE];
vector<pair<int, int> > AA, sp;
void print(int x) {
  W(x);
  u[x] = 1;
  fflush(stdout);
}
int main() {
  int n, m;
  R(n, m);
  for (int i = (1); i <= (2 * n); ++i) {
    R(p[i]);
    AA.push_back({p[i], i});
  }
  sort((AA).begin(), (AA).end());
  for (int i = 0; i < (m); ++i) {
    int a, b;
    R(a, b);
    pp[a] = b;
    pp[b] = a;
    if (p[a] > p[b])
      sp.push_back({a, b});
    else
      sp.push_back({b, a});
  }
  int player;
  R(player);
  int r = n * 2;
  while (r >= 0) {
    r--;
    if (player == 1) {
      bool done = 0;
      while (((int)(sp).size())) {
        if (u[sp.back().first])
          sp.pop_back();
        else {
          print(sp.back().first);
          done = 1;
          break;
        }
      }
      if (!done) {
        while (((int)(AA).size())) {
          if (u[AA.back().second])
            AA.pop_back();
          else {
            print(AA.back().second);
            break;
          }
        }
      }
      player = 3 - player;
    } else {
      int x;
      R(x);
      u[x] = 1;
      if (pp[x] && !u[pp[x]]) {
        r--;
        print(pp[x]);
        continue;
      }
      player = 3 - player;
    }
  }
  return 0;
}
