#include <bits/stdc++.h>
using namespace std;
int a[10010];
int x[10010];
int y[10010];
int kol = 0;
map<int, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= 2 * n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  int t, pred = -1;
  cin >> t;
  if (t == 2) {
    int l;
    cin >> l;
    mp[l]++;
    kol++;
    pred = l;
  }
  while (pred != -1) {
    if (kol == 2 * n) break;
    int fl = 0;
    mp[pred] = 1;
    for (int i = 1; i <= m; i++)
      if (x[i] == pred || y[i] == pred) {
        if (x[i] == pred) {
          mp[y[i]] = 1;
          pred = y[i];
          fl = 1;
        } else {
          mp[x[i]] = 1;
          pred = x[i];
          fl = 1;
        }
      }
    if (fl != 1) break;
    cout << pred << endl;
    fflush(stdout);
    kol++;
    if (kol == 2 * n) break;
    kol++;
    cin >> pred;
  }
  if (pred != -1) mp[pred] = 1;
  for (int i = 1; i <= m; i++) {
    if (kol == 2 * n) break;
    if (mp[x[i]] == 0) {
      if (a[x[i]] >= a[y[i]]) {
        pred = x[i];
      } else
        pred = y[i];
      mp[x[i]] = 1;
      mp[y[i]] = 1;
      cout << pred << endl;
      fflush(stdout);
      kol++;
      if (kol == 2 * n) break;
      cin >> pred;
      kol++;
    }
  }
  while (1) {
    if (kol == 2 * n) break;
    int fl = 0, ma = 0;
    for (int i = 1; i <= 2 * n; i++) {
      if (mp[i] == 0) {
        if (ma < a[i]) {
          fl = i;
          ma = max(ma, a[i]);
        }
      }
    }
    if (fl == 0) break;
    mp[fl] = 1;
    cout << fl << endl;
    fflush(stdout);
    kol++;
    if (kol == 2 * n) break;
    kol++;
    cin >> fl;
    mp[fl] = 1;
  }
  return 0;
}
