#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int p[2005];
  set<pair<int, int> > st;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> p[i];
    st.insert(make_pair(-p[i], i));
  }
  int a, b;
  set<pair<int, pair<int, int> > > prs;
  int f[2005] = {};
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    f[a] = b;
    f[b] = a;
    if (p[a] < p[b]) swap(a, b);
    prs.insert({-p[a], {a, b}});
  }
  int t;
  cin >> t;
  int x, y;
  int N = 2 * n;
  if (t == 1) {
    N--;
    if (!prs.empty()) {
      x = (*(prs.begin())).second.first;
      prs.erase(prs.begin());
      st.erase(st.find({-p[x], x}));
      f[f[x]] = 0;
      f[x] = 0;
    } else {
      x = (*(st.begin())).second;
      st.erase(st.begin());
    }
    cout << x << "\n";
    fflush(stdout);
  }
  while (N > 0) {
    N--;
    cin >> y;
    st.erase(st.find({-p[y], y}));
    if (N == 0) break;
    N--;
    if (f[y]) {
      x = f[y];
      if (p[x] > p[y])
        prs.erase(prs.find({-p[x], {x, y}}));
      else
        prs.erase(prs.find({-p[y], {y, x}}));
      st.erase(st.find({-p[x], x}));
    } else {
      if (!prs.empty()) {
        x = (*(prs.begin())).second.first;
        st.erase(st.find({-p[x], x}));
        prs.erase(prs.begin());
        f[f[x]] = 0;
        f[x] = 0;
      } else {
        x = (*(st.begin())).second;
        st.erase(st.begin());
      }
    }
    cout << x << "\n";
    fflush(stdout);
  }
  return 0;
}
