#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, m, a, b, d, e;
  cin >> n >> m;
  vector<int> temp(2 * n + 1, 0), power(2 * n + 1, 0);
  vector<pair<int, int>> arr, power1;
  pair<int, int> temp1;
  for (int i = 0; i < 2 * n; i++) {
    cin >> temp[i + 1];
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    power[a] = b;
    power[b] = a;
  }
  for (int i = 0; i < 2 * n + 1; i++) {
    if (!power[i + 1]) {
      arr.push_back({temp[i + 1], i + 1});
    } else {
      power1.push_back({temp[i + 1], i + 1});
    }
  }
  sort(arr.begin(), arr.end(), greater<pair<int, int>>());
  sort(power1.begin(), power1.end(), greater<pair<int, int>>());
  vector<bool> check(2 * n + 1, 0);
  int t;
  cin >> t;
  int i = 0, j = 0, k = 0;
  if (t == 1) {
    if (power1.size()) {
      cout << power1[0].second << endl;
      fflush(stdout);
      a = power[power1[0].second];
      power[power1[0].second] = 0;
      power[a] = 0;
      j++;
    } else {
      a = arr[0].second;
      cout << a << endl;
      fflush(stdout);
      check[a] = true;
      k++;
    }
    i++;
  }
  bool flag = 0;
  while (i < n) {
    cin >> a;
    if (power[a]) {
      b = power[a];
      cout << b << endl;
      fflush(stdout);
      power[b] = 0;
      power[a] = 0;
    } else {
      check[a] = true;
      flag = 0;
      while (j < power1.size()) {
        if (power[power1[j].second]) {
          cout << power1[j].second << endl;
          fflush(stdout);
          b = power[power1[j].second];
          power[b] = 0;
          power[power1[j].second] = 0;
          j++;
          flag = 1;
          break;
        }
        j++;
      }
      if (!flag) {
        while (k < arr.size()) {
          if (check[arr[k].second] == false) {
            cout << arr[k].second << endl;
            check[arr[k].second] = true;
            k++;
            break;
          }
          k++;
        }
      }
    }
    i++;
  }
}
