#include <bits/stdc++.h>
using namespace std;
int a[3000] = {0};
bool compareind(int c, int b) { return a[c] > a[b]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int index[3000] = {0};
  int visited[3000] = {0};
  int pair[3000] = {0};
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
    index[i] = i;
  }
  sort(index + 1, index + 2 * n + 1, compareind);
  int x, y;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    pair[x] = y;
    pair[y] = x;
  }
  int t;
  cin >> t;
  int currindex = 1;
  int turns = 0;
  if (t == 2) {
    cin >> x;
    visited[x] = 1;
    while (pair[x]) {
      cout << pair[x] << endl;
      turns++;
      visited[pair[x]] = 1;
      if (turns < n)
        cin >> x;
      else {
        break;
      }
      visited[x] = 1;
    }
  }
  for (int i = 1; i <= 2 * n; i++) {
    if (pair[i] && visited[i] == 0) {
      if (a[i] > a[pair[i]]) {
        cout << i << endl;
        turns++;
      } else {
        cout << pair[i] << endl;
        turns++;
      }
      cin >> x;
      visited[i] = 1;
      visited[pair[i]] = 1;
    }
  }
  while (turns < n) {
    while (visited[index[currindex]] == 1) {
      currindex++;
    }
    cout << index[currindex] << endl;
    visited[index[currindex]] = 1;
    turns++;
    if (turns == n) {
      break;
    }
    cin >> x;
    visited[x] = 1;
  }
  return 0;
}
