#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = (int)4e5 + 5;
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  vector<bool> used(2 * n + 1, false);
  vector<int> power(2 * n + 1);
  unordered_map<int, int> esp;
  multiset<pair<int, int>> ms;
  vector<pair<int, pair<int, int>>> pz;
  for (int i = 1; i <= (2 * n); i++) {
    cin >> power[i];
    ms.insert({power[i], i});
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    esp[a] = b;
    esp[b] = a;
    pz.push_back({abs(power[a] - power[b]), {a, b}});
  }
  sort(pz.begin(), pz.end());
  int t;
  cin >> t;
  int last = -1;
  while (!ms.empty()) {
    if (t == 1) {
      if (last == -1) {
        while (!pz.empty() && used[pz.back().second.first]) pz.pop_back();
        if (!pz.empty()) {
          pair<int, pair<int, int>> cur = pz.back();
          pz.pop_back();
          int a = cur.second.first;
          int b = cur.second.second;
          int select = a;
          if (power[b] > power[a]) select = b;
          ms.erase({power[select], select});
          used[select] = true;
          cout << select << endl;
        } else {
          pair<int, int> cur = *(--ms.end());
          int select = cur.second;
          used[select] = true;
          ms.erase({power[select], select});
          cout << select << endl;
        }
      } else if (last != -1) {
        if (esp[last] != 0 && !used[esp[last]]) {
          int select = esp[last];
          used[select] = true;
          ms.erase({power[select], select});
          cout << select << endl;
        } else {
          while (!pz.empty() && used[pz.back().second.first]) pz.pop_back();
          if (!pz.empty()) {
            pair<int, pair<int, int>> cur = pz.back();
            pz.pop_back();
            int a = cur.second.first;
            int b = cur.second.second;
            int select = a;
            if (power[b] > power[a]) select = b;
            ms.erase({power[select], select});
            used[select] = true;
            cout << select << endl;
          } else {
            pair<int, int> cur = *(--ms.end());
            int select = cur.second;
            used[select] = true;
            ms.erase({power[select], select});
            cout << select << endl;
          }
        }
      }
    } else if (t == 2) {
      cin >> last;
      used[last] = true;
      ms.erase({power[last], last});
    }
    if (t == 1)
      t = 2;
    else
      t = 1;
  }
  return 0;
}
