#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 3;
const long long mod = 1e9 + 7;
int main() {
  long long i = 0;
  long long n, m, a;
  cin >> n >> m;
  map<int, int> ma;
  map<int, int> r, mark, idx, val;
  for (i = 0; i < 2 * n; i++) {
    cin >> a;
    ma[i + 1] = 0;
    val[i + 1] = a;
  }
  int b;
  int cnt = 0;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    r[a] = b;
    r[b] = a;
    cnt++;
  }
  int t;
  cin >> t;
  if (t == 1) {
    for (i = 0; i < n;) {
      if (cnt > 0) {
        for (auto k : r) {
          if (!mark[k.first] && !mark[k.second]) {
            int x = k.first;
            int y = k.second;
            if (val[x] > val[y])
              cout << x << endl;
            else
              cout << y << endl;
            mark[x] = 1;
            mark[y] = 1;
            cnt--;
            fflush(stdout);
            int z;
            cin >> z;
            i++;
            continue;
          }
        }
      }
      if (i == n) return 0;
      int max = 0;
      int idxv = -1;
      for (auto k : ma) {
        if (!mark[k.first]) {
          if (max < val[k.first]) {
            max = val[k.first];
            idxv = k.first;
          }
        }
      }
      cout << idxv << endl;
      mark[idxv] = 1;
      fflush(stdout);
      int x;
      cin >> x;
      i++;
      mark[x] = 1;
    }
  } else {
    for (i = 0; i < n;) {
      int x;
      cin >> x;
      mark[x] = 1;
      if (r[x]) {
        cnt--;
        cout << r[x] << endl;
        i++;
        mark[r[x]] = 1;
        mark[x] = 1;
        fflush(stdout);
        if (i == n) return 0;
        continue;
      } else {
        while (i < n) {
          if (cnt > 0) {
            for (auto k : r) {
              if (!mark[k.first] && !mark[k.second]) {
                int x = k.first;
                int y = k.second;
                if (val[x] > val[y])
                  cout << x << endl;
                else
                  cout << y << endl;
                mark[x] = 1;
                mark[y] = 1;
                cnt--;
                fflush(stdout);
                int z;
                cin >> z;
                i++;
                continue;
              }
            }
          }
          int max = 0;
          int idxv = 0;
          for (auto k : ma) {
            if (!mark[k.first]) {
              if (max < val[k.first]) {
                max = val[k.first];
                idxv = k.first;
              }
            }
          }
          cout << idxv << endl;
          i++;
          mark[idxv] = 1;
          fflush(stdout);
          if (i == n) {
            return 0;
          }
          int x;
          cin >> x;
          mark[x] = 1;
        }
        if (i == n) return 0;
        for (auto a : ma) {
          if (!mark[a.first]) {
            cout << a.first << endl;
            fflush(stdout);
          }
        }
        return 0;
      }
    }
  }
}
