#include <bits/stdc++.h>
using namespace std;
const int N = 2e3;
int n, m, p[N], with[N], have = -1;
bool taken[N];
vector<int> sp, nor;
bool comp(int a, int b) { return p[a] < p[b]; }
int main() {
  scanf("%d%d", &n, &m);
  memset(with, -1, sizeof with);
  for (int i = 0; i < 2 * n; i++) scanf("%d", p + i);
  for (int i = 0, a, b; i < m; i++) {
    scanf("%d%d", &a, &b);
    with[--a] = --b;
    with[b] = a;
  }
  for (int i = 0; i < 2 * n; i++)
    if (with[i] != -1)
      sp.push_back(i);
    else
      nor.push_back(i);
  sort(sp.begin(), sp.end(), comp);
  sort(nor.begin(), nor.end(), comp);
  int t;
  scanf("%d", &t);
  t = t == 1;
  for (int i = 0; i < 2 * n; i++, t ^= 1) {
    if (t) {
      if (have != -1) {
        cout << have + 1 << endl;
        taken[have] = 1;
        continue;
      }
      while (sp.size() && taken[sp.back()]) sp.pop_back();
      if (sp.size()) {
        cout << sp.back() + 1 << endl;
        taken[sp.back()] = 1;
        sp.pop_back();
        continue;
      }
      while (taken[nor.back()]) nor.pop_back();
      cout << nor.back() + 1 << endl;
      nor.pop_back();
      continue;
    }
    scanf("%d", &have);
    have -= 1;
    taken[have] = 1;
    if (with[have] != -1) have = with[have];
    if (taken[have]) have = -1;
  }
}
