#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 1005;
int n, m, t, x;
struct node {
  int p, f, to;
} a[maxn * 2];
int vis[maxn * 2];
int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &a[i].p);
  }
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    a[u].to = v;
    a[u].f = 1;
    a[v].to = u;
    a[v].f = 1;
  }
  scanf("%d", &t);
  for (int i = 1; i <= n; i++) {
    if (t == 1) {
      int ans = 0, pos = -1;
      for (int j = 1; j <= 2 * n; j++) {
        if (vis[j]) continue;
        if (a[j].f && a[j].p >= a[a[j].to].p) {
          if (a[j].p > ans) {
            ans = a[j].p;
            pos = j;
          }
        }
      }
      if (pos != -1) {
        vis[pos] = 1;
        printf("%d\n", pos);
        fflush(stdout);
      } else {
        int ans = 0, pos;
        for (int j = 1; j <= 2 * n; j++) {
          if (vis[j]) continue;
          if (a[j].p > ans) {
            ans = a[j].p;
            pos = j;
          }
        }
        vis[pos] = 1;
        printf("%d\n", pos);
        fflush(stdout);
      }
      scanf("%d", &x);
      vis[x] = 1;
    } else {
      scanf("%d", &x);
      vis[x] = 1;
      if (a[x].f && !vis[a[x].to]) {
        printf("%d\n", a[x].to);
        fflush(stdout);
        vis[a[x].to] = 1;
      } else {
        int ans = 0, pos = -1;
        for (int j = 1; j <= 2 * n; j++) {
          if (vis[j]) continue;
          if (a[j].f && a[j].p >= a[a[j].to].p) {
            if (a[j].p > ans) {
              ans = a[j].p;
              pos = j;
            }
          }
        }
        if (pos != -1) {
          vis[pos] = 1;
          printf("%d\n", pos);
          fflush(stdout);
        } else {
          int ans = 0, pos;
          for (int j = 1; j <= 2 * n; j++) {
            if (vis[j]) continue;
            if (a[j].p > ans) {
              ans = a[j].p;
              pos = j;
            }
          }
          vis[pos] = 1;
          printf("%d\n", pos);
          fflush(stdout);
        }
      }
    }
  }
  return 0;
}
