#include <bits/stdc++.h>
using namespace std;
struct vec {
  int p;
  int x;
  int y;
  int t;
} v[2001];
int w[1001];
bool comp(vec a, vec b) { return (a.p > b.p); }
int main() {
  int n, m, i, x, y, t, OK, J, poz, max1, j, AI;
  cin >> n >> m;
  for (i = 1; i <= 2 * n; ++i) {
    cin >> v[i].p;
    v[i].t = 0;
  }
  for (i = 1; i <= m; ++i) {
    cin >> x >> y;
    w[i] = x;
    v[x].x = 1;
    v[x].y = y;
    v[y].x = 1;
    v[y].y = x;
  }
  cin >> t;
  if (t == 1) {
    J = 1;
    for (i = 1; i <= n; ++i) {
      OK = 0;
      for (j = J; j <= m; ++j)
        if (v[w[j]].t == 0) {
          OK = 1;
          if (v[w[j]].p > v[v[w[j]].y].p) {
            v[w[j]].t = 1;
            J++;
            cout << w[j] << endl;
            cout.flush();
            break;
          } else {
            v[v[w[j]].y].t = 1;
            J++;
            cout << v[w[j]].y << endl;
            cout.flush();
            break;
          }
        }
      if (OK == 0) {
        max1 = 0;
        for (j = 1; j <= 2 * n; ++j)
          if (v[j].t == 0 && v[j].p > max1) {
            max1 = v[j].p;
            poz = j;
          }
        v[poz].t = 1;
        cout << poz << endl;
        cout.flush();
      }
      cin >> AI;
      v[AI].t = 1;
    }
  } else if (t == 2) {
    for (i = 1; i <= n; ++i) {
      cin >> x;
      v[x].t = 1;
      if (v[x].x == 1 && v[v[x].y].t == 0) {
        v[v[x].y].t = 1;
        cout << v[x].y << endl;
        cout.flush();
      } else {
        OK = 0;
        for (j = 1; j <= m; ++j)
          if (v[w[j]].t == 0) {
            OK = 1;
            if (v[w[j]].p > v[v[w[j]].y].p) {
              v[w[j]].t = 1;
              J++;
              cout << w[j] << endl;
              cout.flush();
              break;
            } else {
              v[v[w[j]].y].t = 1;
              J++;
              cout << v[w[j]].y << endl;
              cout.flush();
              break;
            }
          }
        if (OK == 0) {
          max1 = 0;
          for (j = 1; j <= 2 * n; ++j)
            if (v[j].t == 0 && v[j].p > max1) {
              max1 = v[j].p;
              poz = j;
            }
          v[poz].t = 1;
          cout << poz << endl;
          cout.flush();
        }
      }
    }
  }
  return 0;
}
