#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
const int INF_INT = 2e9 + 100;
const long long POLTOS = 50;
const long long SOTKA = 100;
const long long P = 1e9 + 7;
const long double eps = 1e-11;
const long long base = 1000 * 1000 * 1000;
const long long M = 3050;
const long long MAXN = 1e6 + 1;
const long long MAXN1 = 2 * 1e2;
const long long N = 300;
const long double pi = acos(-1);
const int mod = 1e9 + 7;
const int S_M = 20;
const long long LEN = 96;
const long long DMOD = 500000004;
const long long PR = 32000;
int n, m;
vector<int> s, s2;
void solve1(vector<int> a, vector<int> cont) {
  vector<bool> used(2 * n, false);
  for (int i = 0; i < n; ++i) {
    while (!s.empty() && used[s.back()]) {
      s.pop_back();
    }
    while (!s2.empty() && used[s2.back()]) {
      s2.pop_back();
    }
    if (s.empty()) {
      cout << s2.back() + 1 << '\n';
      used[s2.back()] = true;
      s2.pop_back();
    } else {
      cout << s.back() + 1 << '\n';
      used[s.back()] = true;
      s.pop_back();
    }
    cout.flush();
    int first;
    cin >> first;
    --first;
    used[first] = true;
  }
}
void solve2(vector<int> a, vector<int> cont) {
  vector<bool> used(2 * n, false);
  for (int i = 0; i < n; ++i) {
    int first;
    cin >> first;
    --first;
    used[first] = true;
    if (cont[first] != -1 && !used[cont[first]]) {
      cout << cont[first] + 1 << '\n';
      used[cont[first]] = true;
    } else {
      while (!s.empty() && used[s.back()]) {
        s.pop_back();
      }
      while (!s2.empty() && used[s2.back()]) {
        s2.pop_back();
      }
      if (s.empty()) {
        cout << s2.back() + 1 << '\n';
        used[s2.back()] = true;
        s2.pop_back();
      } else {
        cout << s.back() + 1 << '\n';
        used[s.back()] = true;
        s.pop_back();
      }
    }
    cout.flush();
  }
}
int main() {
  cin >> n >> m;
  vector<int> a(2 * n);
  for (auto &i : a) {
    cin >> i;
  }
  vector<int> cont(2 * n, -1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    cont[a] = b;
    cont[b] = a;
  }
  vector<bool> used(2 * n, false);
  for (int i = 0; i < 2 * n; ++i) {
    if (cont[i] == -1 || used[i] || used[cont[i]]) {
      continue;
    }
    if (a[i] > a[cont[i]]) {
      s.emplace_back(i);
    } else {
      s.emplace_back(cont[i]);
    }
    used[i] = used[cont[i]] = true;
  }
  sort(s.begin(), s.end(),
       [&](int first, int second) { return a[first] < a[second]; });
  for (int i = 0; i < 2 * n; ++i) {
    if (!used[i]) {
      s2.emplace_back(i);
    }
  }
  sort(s2.begin(), s2.end(),
       [&](int first, int second) { return a[first] < a[second]; });
  fill(used.begin(), used.end(), false);
  int t;
  cin >> t;
  if (t == 1) {
    solve1(a, cont);
  } else {
    solve2(a, cont);
  }
  return 0;
}
