#include <bits/stdc++.h>
using namespace std;
using LD = long double;
using PLL = pair<long long, long long>;
using VII = vector<pair<int, int>>;
template <class T>
bool power_2(T v) {
  static_assert(std::is_integral<T>::value, "type should be integral");
  return v && !(v & (v - 1));
}
template <class T>
istream& operator>>(istream& st, vector<T>& container) {
  for (auto& u : container) st >> u;
  return st;
}
template <class T>
ostream& operator<<(ostream& st, const vector<T>& container) {
  for (auto& u : container) st << u << '\n';
  return st;
}
template <class T, size_t N>
istream& operator>>(istream& st, array<T, N>& container) {
  for (auto& u : container) st >> u;
  return st;
}
template <class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N>& container) {
  for (auto u : container) st << u << ' ';
  return st;
}
template <class T, class U>
istream& operator>>(istream& st, pair<T, U>& p) {
  st >> p.first >> p.second;
  return st;
}
template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p) {
  st << p.first << ' ' << p.second;
  return st;
}
template <class T, class U, class V>
pair<T, U> operator*(pair<T, U> p, V val) {
  return {p.first * val, p.second * val};
}
template <class T, class U, class V>
pair<T, U> operator/(pair<T, U> p, V val) {
  return {p.first / val, p.second / val};
}
template <class T, class U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
  return {a.first - b.first, a.second - b.second};
}
template <class T, class U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
  return {a.first + b.first, a.second + b.second};
}
template <class T>
T dotProduct(pair<T, T> a, pair<T, T> b) {
  return a.first * b.first + a.second * b.second;
}
template <class T>
T crossProduct(pair<T, T> a, pair<T, T> b) {
  return a.first * b.second - a.second * b.first;
}
template <class T>
T lengthPow(pair<T, T> a) {
  return a.first * a.first + a.second * a.second;
}
template <class T>
LD length(pair<T, T> a) {
  return sqrt(lengthPow(a));
}
const int N = 1e5 + 57, inf = 1e9 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 7;
const long double PI = acos(-1);
const LD EPS = 1e-12;
int moce[N];
bitset<N> uzyty;
vector<pair<int, int>> pary;
int n;
int dajPare() {
  int maxi = pary[0].first;
  int id = 0;
  for (int i = 1; i < pary.size(); ++i) {
    int a = pary[i].first;
    if (moce[a] > moce[maxi]) {
      maxi = a;
      id = i;
    }
  }
  pary.erase(pary.begin() + id);
  return maxi;
}
int dajZwykly() {
  int id = 0;
  while (uzyty[id]) ++id;
  for (int i = id + 1; i < 2 * n; ++i) {
    if (!uzyty[i] && moce[i] > moce[id]) id = i;
  }
  uzyty[id] = 1;
  return id;
}
int dajDoPary(int a) {
  for (int i = 0; i < pary.size(); ++i) {
    if (pary[i].first == a) {
      int nr = pary[i].second;
      pary.erase(pary.begin() + i);
      return nr;
    }
    if (pary[i].second == a) {
      int nr = pary[i].first;
      pary.erase(pary.begin() + i);
      return nr;
    }
  }
  return -1;
}
void wypisz(int nr) {
  uzyty[nr] = 1;
  cout << nr + 1 << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(9);
  int m;
  cin >> n >> m;
  for (int i = 0; i < 2 * n; ++i) {
    cin >> moce[i];
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (moce[a] < moce[b]) swap(a, b);
    pary.push_back({a, b});
  }
  int t;
  cin >> t;
  int moja = (t == 1);
  int musi = -1;
  int ileZostalo = 2 * n;
  while (ileZostalo--) {
    if (moja) {
      if (musi != -1) {
        wypisz(musi);
        musi = -1;
      } else {
        if (pary.size()) {
          wypisz(dajPare());
        } else
          wypisz(dajZwykly());
      }
    } else {
      int nr;
      cin >> nr;
      --nr;
      if (nr == -2) {
        return 0;
      }
      uzyty[nr] = 1;
      musi = dajDoPary(nr);
    }
    moja ^= 1;
  }
  return 0;
}
