#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  deque<pair<int, int> > p(2 * n + 1);
  for (int i = 1; i <= 2 * n; i++) {
    cin >> p[i].first;
    p[i].second = i;
  }
  deque<pair<int, pair<int, int> > > super(m);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    super[i].second.first = u;
    super[i].second.second = v;
    super[i].first = abs(p[u].first - p[v].second);
  }
  sort(super.rbegin(), super.rend());
  vector<bool> isRemoved(2 * n + 1);
  int t;
  cin >> t;
  int k = n;
  if (t == 1) {
    if (m == 0) {
      sort(p.rbegin(), p.rend());
      cout << p.front().second << endl;
      isRemoved[p.front().second] = true;
      p.pop_front();
    } else {
      int u = super.front().second.first;
      int v = super.front().second.second;
      if (p[u].first > p[v].first) {
        cout << u << endl;
        isRemoved[u] = true;
        isRemoved[v] = true;
      } else {
        cout << v << endl;
        isRemoved[v] = true;
        isRemoved[u] = true;
      }
      super.pop_front();
    }
    k--;
  }
  bool isSorted = false;
  while (k != 0) {
    int h;
    cin >> h;
    auto s = super.begin();
    if (isRemoved[h] == true) {
      s = super.end();
    }
    isRemoved[h] = true;
    for (; s != super.end(); s++) {
      int u = (*s).second.first;
      int v = (*s).second.second;
      if (u == h) {
        cout << v << endl;
        isRemoved[u] = true;
        isRemoved[v] = true;
        k--;
        break;
      } else if (v == h) {
        cout << u << endl;
        isRemoved[u] = true;
        isRemoved[v] = true;
        k--;
        break;
      }
    }
    if (s != super.end()) {
      super.erase(s);
      continue;
    }
    if (super.size() != 0) {
      int u = super.front().second.first;
      int v = super.front().second.second;
      if (p[u].first > p[v].first) {
        cout << u << endl;
        isRemoved[u] = true;
        isRemoved[v] = true;
      } else {
        cout << v << endl;
        isRemoved[u] = true;
        isRemoved[v] = true;
      }
      super.pop_front();
      k--;
    } else {
      if (isSorted == false) {
        sort(p.rbegin(), p.rend());
        isSorted = true;
      }
      for (auto v : p) {
        if (!isRemoved[v.second]) {
          cout << v.second << endl;
          isRemoved[v.second] = true;
          k--;
          break;
        }
      }
    }
  }
  if (t == 1) {
    int tmp;
    cin >> tmp;
  }
  return 0;
}
