#include <bits/stdc++.h>
using namespace std;
struct srt {
  int ind, val;
} a[2005];
struct cor {
  int x, y, dif;
} m[2005];
int n, M, x, v[2005], t, bij[2005];
bool comp(srt x, srt y) { return (x.val < y.val); }
bool comp1(cor a, cor b) { return (a.dif < b.dif); }
void solve1() {
  for (int z = 1; z <= M; ++z) {
    cout << m[z].x << '\n';
    cout.flush();
    v[m[z].x] = 0;
    cin >> x;
    v[x] = 0;
  }
  t = M;
  M = 2 * n;
  for (int z = t + 1; z <= n; ++z) {
    while (v[a[M].ind] == 0) --M;
    cout << a[M].ind << '\n';
    cout.flush();
    v[a[M].ind] = 0;
    --M;
    cin >> x;
    v[x] = 0;
  }
}
void solve2() {
  t = M;
  M = 2 * n;
  for (int z = 1; z <= n; ++z) {
    cin >> x;
    v[x] = 0;
    if (v[bij[x]]) {
      x = bij[x];
      v[x] = 0;
      cout << x << '\n';
      cout.flush();
    } else {
      while (v[m[t].x] == 0 && t) --t;
      if (t) {
        cout << m[t].x << '\n';
        cout.flush();
        v[m[t].x] = 0;
      } else {
        while (v[a[M].ind] == 0) --M;
        cout << a[M].ind << '\n';
        cout.flush();
        v[a[M].ind] = 0;
      }
    }
  }
}
int main() {
  cin >> n >> M;
  for (int i = 1; i <= 2 * n; ++i) {
    cin >> v[i];
    a[i].val = v[i];
    a[i].ind = i;
  }
  sort(a + 1, a + 2 * n + 1, comp);
  for (int i = 1; i <= M; ++i) {
    cin >> m[i].x >> m[i].y;
    if (v[m[i].y] > v[m[i].x]) swap(m[i].y, m[i].x);
    m[i].dif = v[m[i].x] - v[m[i].y];
    bij[m[i].x] = m[i].y;
    bij[m[i].y] = m[i].x;
  }
  sort(m + 1, m + M + 1, comp1);
  cin >> t;
  if (t == 1)
    solve1();
  else
    solve2();
  return 0;
}
