#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
const long double eps = 1e-12;
const long double Pi = acos(-1);
const long long md = 1e9 + 7;
using namespace std;
long long n, m, p[10100], f[10100], x, y;
pair<long long, long long> d[10100];
bool used[10100];
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (f[b.second] && f[a.second]) {
    return a.first > b.first;
  }
  if (!f[b.second] && !f[a.second]) {
    return a.first > b.first;
  }
  return f[a.second];
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 1; i <= 2 * n; i++) {
    cin >> p[i];
    d[i].first = p[i];
    d[i].second = i;
  }
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    f[x] = y;
    f[y] = x;
    d[x].first = p[x] - p[y];
    d[y].first = p[y] - p[x];
  }
  sort(d + 1, d + 2 * n + 1, cmp);
  long long t;
  cin >> t;
  long long cnt = 2 * n;
  long long it = 1;
  while (cnt) {
    if (t == 2) {
      cnt--;
      cin >> x;
      used[x] = true;
      if (f[x]) {
        cout << f[x] << "\n";
        used[f[x]] = true;
        cnt--;
        cout << flush;
        ;
      } else {
        t = 3 - t;
      }
    } else {
      for (; it <= 2 * n; it++) {
        if (used[d[it].second]) continue;
        cout << d[it].second << "\n";
        used[d[it].second] = true;
        cout << flush;
        ;
        if (f[d[it].second]) {
          cin >> x;
          used[x] = true;
          cnt--;
          t = 3 - t;
        }
        break;
      }
      cnt--;
      t = 3 - t;
    }
  }
  return 0;
}
