#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
pair<int, int> q[maxn];
vector<int> ver;
int n, m, a[maxn], pr[maxn], pick[maxn];
bool cmp(int x, int y) { return a[x] > a[y]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n * 2; i++) cin >> a[i];
  for (int i = 1, x, y; i <= m; i++) {
    cin >> x >> y;
    if (a[x] < a[y]) swap(x, y);
    q[i] = pair<int, int>(x, y);
    pr[x] = y;
    pr[y] = x;
  }
  for (int i = 1; i <= n * 2; i++)
    if (pr[i] == 0) ver.push_back(i);
  int turn;
  cin >> turn;
  if (turn == 1) {
    for (int i = 1, x; i <= m; i++) {
      cout << q[i].first << "\n";
      pick[q[i].first] = 1;
      fflush(stdout);
      cin >> x;
      pick[x] = 1;
    }
    sort(ver.begin(), ver.end(), cmp);
    for (int i = 1; i <= ver.size() / 2; i++)
      for (int j = 0, x; j < ver.size(); j++)
        if (!pick[ver[j]]) {
          cout << ver[j] << "\n";
          pick[ver[j]] = 1;
          fflush(stdout);
          cin >> x;
          pick[x] = 1;
          break;
        }
  } else {
    for (int t = 1, x; t <= n; t++) {
      fflush(stdout);
      cin >> x;
      pick[x] = 1;
      if (pr[x] && !pick[pr[x]]) {
        cout << pr[x] << "\n";
        pick[pr[x]] = 1;
        continue;
      } else {
        for (int i = 1, x; i <= m; i++)
          if (!pick[q[i].first]) {
            cout << q[i].first << "\n";
            pick[q[i].first] = 1;
            fflush(stdout);
            cin >> x;
            pick[x] = 1;
          }
        sort(ver.begin(), ver.end(), cmp);
        bool flag = 1;
        while (flag) {
          flag = 0;
          for (int j = 0; j < ver.size(); j++)
            if (!pick[ver[j]]) {
              cout << ver[j] << "\n";
              pick[ver[j]] = 1;
              break;
            }
          for (int j = 0; j < ver.size(); j++)
            if (!pick[ver[j]]) {
              flag = 1;
              break;
            }
          if (flag) {
            fflush(stdout);
            cin >> x;
            pick[x] = 1;
          }
        }
        break;
      }
    }
  }
}
