#include <bits/stdc++.h>
using namespace std;
int a[100100];
int first[100100];
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  set<pair<int, int> > st;
  set<pair<int, int> > st1;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
    st.insert({a[i], i});
  }
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    first[x] = y;
    first[y] = x;
    st1.insert({max(a[x], a[y]), min(x, y)});
  }
  int pr = 0;
  int t;
  cin >> t;
  t %= 2;
  for (int i = 0; i < 2 * n; i++) {
    if (t) {
      if (first[pr] && st.count({a[first[pr]], first[pr]})) {
        cout << first[pr] << "\n";
        cout.flush();
        st.erase({a[first[pr]], first[pr]});
        pr = first[pr];
      } else if (!st1.empty()) {
        int z = (--st1.end())->second;
        if (a[z] < a[first[z]]) z = first[z];
        st1.erase(--st1.end());
        cout << z << "\n";
        pr = z;
        cout.flush();
        st.erase({a[z], z});
      } else {
        int z = (--st.end())->second;
        cout << z << "\n";
        pr = z;
        cout.flush();
        st.erase({a[z], z});
      }
    } else {
      cin >> x;
      if (first[x] && st.count({a[first[x]], first[x]})) {
        st1.erase({max(a[x], a[first[x]]), min(x, first[x])});
      }
      st.erase({a[x], x});
      pr = x;
    }
    t = !t;
  }
  return 0;
}
