#include <bits/stdc++.h>
using namespace std;
int p[2005];
pair<int, int> d[2005];
int idx[2005];
bool vis[2005];
vector<pair<int, int> > v;
void print(int a) {
  printf("%d\n", a);
  fflush(stdout);
}
int main() {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  v.push_back(pair<int, int>(0, 0));
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &p[i]);
    v.push_back(pair<int, int>(p[i], i));
  }
  sort(v.begin(), v.end());
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    if (p[a] > p[b]) swap(a, b);
    d[i] = pair<int, int>(a, b);
    idx[a] = i;
    idx[b] = i;
  }
  int t;
  scanf("%d", &t);
  if (t == 1) {
    for (int i = 1; i <= m; i++) {
      print(d[i].second);
      scanf("%d", &a);
      vis[d[i].second] = 1;
      vis[a] = 1;
    }
    for (int i = 2 * n; i >= 1; i--) {
      int j = v[i].second;
      if (vis[j]) continue;
      print(j);
      scanf("%d", &a);
      vis[a] = 1;
      vis[j] = 1;
    }
  } else {
    int r = 0;
    while (r <= 2 * n) {
      scanf("%d", &a);
      vis[a] = 1;
      r++;
      if (idx[a] == 0) break;
      int i = idx[a];
      if (a == d[i].first)
        print(d[i].second);
      else
        print(d[i].first);
      r++;
      vis[d[i].first] = 1;
      vis[d[i].second] = 1;
    }
    for (int i = 1; i <= m; i++) {
      if (vis[d[i].second] == 1) continue;
      print(d[i].second);
      scanf("%d", &a);
      r += 2;
      vis[d[i].second] = 1;
      vis[a] = 1;
    }
    for (int i = 2 * n; i >= 1; i--) {
      int j = v[i].second;
      if (vis[j]) continue;
      print(j);
      r++;
      if (r <= 2 * n) scanf("%d", &a);
      r++;
      vis[a] = 1;
      vis[j] = 1;
    }
  }
}
