#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  int used[2001] = {0};
  vector<pair<int, int>> p;
  vector<pair<int, bool>> nevazhno;
  vector<pair<int, int>> pary;
  int x, a, b;
  for (int i = 0; i < 2 * n; i++) {
    cin >> x;
    nevazhno.emplace_back(x, 0);
  }
  int sa, sb;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    used[a] = 1;
    used[b] = 1;
    sa = nevazhno[a].first;
    sb = nevazhno[b].first;
    nevazhno[a].second = 1;
    nevazhno[b].second = 1;
    if (sa > sb)
      pary.emplace_back(a, b);
    else
      pary.emplace_back(b, a);
  }
  for (int i = 0; i < 2 * n; i++) {
    if (!nevazhno[i].second) p.emplace_back(nevazhno[i].first, i);
  }
  sort(p.begin(), p.end());
  sort(pary.begin(), pary.end());
  int t;
  cin >> t;
  if (t == 1) {
    if (m > 0) {
      for (int i = pary.size() - 1; (i >= 0) && (n > 0); i--) {
        cout << pary[i].first + 1;
        n--;
        cout << '\n';
        cout.flush();
        if (n > 0) {
          cin >> x;
          if (x == -1) return 0;
        }
      }
    }
    for (int i = p.size() - 1; (i >= 0) && (n > 0); i--) {
      if (used[p[i].second] != 2) {
        cout << p[i].second + 1;
        n--;
        cout << '\n';
        cout.flush();
        if (n > 0) {
          cin >> x;
          if (x == -1) return 0;
          x--;
          used[x] = 2;
        }
      }
    }
  } else {
    int y = -1;
    while (n > 0) {
      y = -1;
      cin >> x;
      if (x == -1) return 0;
      x--;
      used[x] = 2;
      for (int j = 0; j < int(pary.size()); j++) {
        if (pary[j].first == x) {
          y = pary[j].second;
          break;
        } else if (pary[j].second == x) {
          y = pary[j].first;
          break;
        }
      }
      if (y == -1) break;
      used[y] = 2;
      cout << y + 1;
      cout << '\n';
      cout.flush();
      n--;
      m--;
    }
    if (m > 0) {
      for (int i = pary.size() - 1; (i >= 0) && (n > 0); i--) {
        if (used[pary[i].first] != 2) {
          cout << pary[i].first + 1;
          n--;
          cout << '\n';
          cout.flush();
          if (n > 0) {
            cin >> x;
            if (x == -1) return 0;
          }
        }
      }
    }
    for (int i = p.size() - 1; (i >= 0) && (n > 0); i--) {
      if (used[p[i].second] != 2) {
        cout << p[i].second + 1;
        n--;
        cout << '\n';
        cout.flush();
        if (n > 0) {
          cin >> x;
          if (x == -1) return 0;
          x--;
          used[x] = 2;
        }
      }
    }
  }
}
