#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, MAX = INT_MAX, MAXN = 2e5 + 5;
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &i : v) cin >> i;
  return in;
}
template <typename T>
istream &operator>>(istream &in, pair<T, T> &p) {
  cin >> p.first >> p.second;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
  for (auto &i : v) cout << i << " ";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, pair<T, T> &p) {
  cout << p.first << " " << p.second << " ";
  return out;
}
long long find(vector<long long> &p, vector<long long> &vis,
               map<long long, long long> &sp, long long n) {
  long long mx = 0, spmx = 0, i;
  for (i = 1; i <= n; i++) {
    if (sp.find(i) != sp.end()) {
      if (!vis[i] && p[i] > p[spmx]) spmx = i;
    } else {
      if (!vis[i] && p[i] > p[mx]) mx = i;
    }
  }
  if (spmx)
    return spmx;
  else
    return mx;
}
void solve() {
  long long n, m, a, b, t, cnt = 0;
  cin >> n >> m;
  n *= 2;
  vector<long long> p(n), vis(n + 1);
  cin >> p;
  p.insert(p.begin(), 0);
  map<long long, long long> sp;
  while (m--) {
    cin >> a >> b;
    sp[a] = b;
    sp[b] = a;
  }
  cin >> t;
  if (t == 1) {
    long long pos = find(p, vis, sp, n);
    vis[pos] = 1;
    cout << pos << endl;
    cnt++;
  }
  while (cnt < n) {
    long long pos;
    cin >> pos;
    vis[pos] = 1;
    cnt++;
    if (cnt < n) {
      if (sp.find(pos) != sp.end() && !vis[sp[pos]])
        pos = sp[pos];
      else
        pos = find(p, vis, sp, n);
      cout << pos << endl;
      vis[pos] = 1;
      cnt++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
