#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1000000000000000000;
int MOD(int a, int b) {
  if (a > b)
    return a - b;
  else
    return b - a;
}
int max3(int a, int b, int c) { return max(c, max(a, b)); }
int min3(int a, int b, int c) { return min(a, min(b, c)); }
long long int power(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
long long int logg(long long int a) {
  long long int x = 0;
  while (a > 1) {
    x++;
    a /= 2;
  }
  return x;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int abso(long long int x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
long long int ceiling(long long int a, long long int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> p(2 * n + 1);
  for (int i = 1; i <= 2 * n; i++) {
    cin >> p[i];
  }
  set<pair<int, int>> g;
  set<pair<int, pair<int, int>>> g2;
  map<int, int> m1;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    m1[a] = b;
    m1[b] = a;
    if (p[a] > p[b]) {
      g2.insert(make_pair(p[a] - p[b], make_pair(a, b)));
    } else {
      g2.insert(make_pair(p[b] - p[a], make_pair(b, a)));
    }
  }
  for (int i = 1; i <= 2 * n; i++) {
    g.insert(make_pair(p[i], i));
  }
  int t;
  cin >> t;
  if (t == 1) {
    for (int i = 0; i < 2 * n; i++) {
      if (i % 2 == 0) {
        if (!g2.empty()) {
          auto it = g2.end();
          it--;
          int x1 = (*it).second.first;
          cout << x1 << endl;
          g2.erase(it);
          g.erase(make_pair(p[x1], x1));
          int x;
          cin >> x;
          g.erase(make_pair(p[x], x));
          i++;
        } else {
          auto it = g.end();
          it--;
          cout << (*it).second << endl;
          g.erase(it);
        }
      } else {
        int x;
        cin >> x;
        g.erase(make_pair(p[x], x));
      }
    }
  } else {
    for (int i = 0; i < 2 * n; i++) {
      if (i % 2 == 0) {
        int x;
        cin >> x;
        g.erase(make_pair(p[x], x));
        if (m1.find(x) != m1.end()) {
          cout << m1[x] << endl;
          g.erase(make_pair(p[m1[x]], m1[x]));
          if (p[x] > p[m1[x]]) {
            g2.erase(make_pair(p[x] - p[m1[x]], make_pair(x, m1[x])));
          } else {
            if (p[x] < p[m1[x]]) {
              g2.erase(make_pair(-(p[x] - p[m1[x]]), make_pair(m1[x], x)));
            } else {
              if (g2.find(make_pair(-(p[x] - p[m1[x]]), make_pair(m1[x], x))) !=
                  g2.end()) {
                g2.erase(g2.find(
                    make_pair(-(p[x] - p[m1[x]]), make_pair(m1[x], x))));
              } else {
                g2.erase(make_pair(p[x] - p[m1[x]], make_pair(x, m1[x])));
              }
            }
          }
          i++;
        }
      } else {
        if (!g2.empty()) {
          auto it = g2.end();
          it--;
          int x1 = (*it).second.first;
          cout << x1 << endl;
          g2.erase(it);
          g.erase(make_pair(p[x1], x1));
          int x;
          cin >> x;
          g.erase(make_pair(p[x], x));
          i++;
        } else {
          auto it = g.end();
          it--;
          cout << (*it).second << endl;
          g.erase(it);
        }
      }
    }
  }
}
