#include <bits/stdc++.h>
using namespace std;
int pairs[10010];
int a[10010];
bool visited[10010];
vector<int> indices[10010];
int n, m, b, c, d, e, t, yourtaken, mytaken;
int paired;
bool pairtojoin;
void printvisited() {
  cout << "visited" << '\n';
  for (int i = 1; i <= 2 * n; i++) {
    cout << visited[i] << " ";
  }
}
vector<pair<int, int> > remaining;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << setprecision(3) << fixed;
  cin >> n >> m;
  int y = (2 * n);
  for (int i = 1; i <= y; i++) {
    cin >> a[i];
    indices[a[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> b >> c;
    if (a[b] < a[c]) {
      remaining.emplace_back(c, b);
    } else {
      if (a[b] > a[c]) {
        remaining.emplace_back(b, c);
      }
    }
    pairs[c] = b;
    pairs[b] = c;
  }
  sort(a + 1, a + y + 1);
  cin >> t;
  int myturns = n;
  if (t == 1) {
    if (remaining.size() > 0) {
      int gg = remaining[remaining.size() - 1].first;
      cout << gg << '\n';
      visited[gg] = true;
      if (pairs[gg]) {
        paired = gg;
        pairtojoin = true;
      }
      mytaken = gg;
      cout.flush();
      myturns--;
    } else {
      for (int j = y; j >= 1; j--) {
        for (int index : indices[a[j]]) {
          if (!visited[index]) {
            visited[index] = true;
            cout << index << '\n';
            cout.flush();
            if (pairs[index]) {
              pairtojoin = true;
            }
            paired = pairs[index];
            mytaken = index;
            j = 0;
            break;
          }
        }
      }
      myturns--;
    }
  }
  for (int i = 1; i <= n; i++) {
    cin >> yourtaken;
    visited[yourtaken] = true;
    if (pairs[yourtaken]) {
      if (pairtojoin) {
        pairtojoin = false;
        paired = 0;
      } else {
        paired = yourtaken;
        pairtojoin = true;
      }
    } else {
      paired = 0;
      pairtojoin = false;
    }
    if (myturns--) {
      if (pairtojoin && paired) {
        cout << pairs[paired] << '\n';
        visited[pairs[paired]] = true;
        paired = 0;
        pairtojoin = false;
        cout.flush();
      } else {
        paired = 0;
        mytaken = 0;
        for (auto pa : remaining) {
          if (!visited[pa.first]) {
            visited[pa.first] = true;
            cout << pa.first << '\n';
            cout.flush();
            if (pairs[pa.first]) {
              pairtojoin = true;
            }
            paired = pairs[pa.first];
            mytaken = pa.first;
            break;
          }
        }
        if (mytaken == 0) {
          for (int j = y; j >= 1; j--) {
            for (int index : indices[a[j]]) {
              if (!visited[index]) {
                visited[index] = true;
                cout << index << '\n';
                cout.flush();
                if (pairs[index]) {
                  pairtojoin = true;
                }
                paired = pairs[index];
                mytaken = index;
                j = 0;
                break;
              }
            }
          }
        }
      }
    }
  }
  return 0;
}
