#include void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } int main() { int n, k, x; static int a[100000], b[100000], c[100000]; static int cup[100000]; int i; scanf("%d %d %d", &n, &k, &x); for (i = 0; i < n; i++) cup[i] = i + 1; for (i = 0; i < k; i++) { if (i == x - 1) { getchar(); while (getchar() != '\n'); continue; } scanf("%d %d", &a[i], &b[i]); if (i < x) swap(&cup[a[i] - 1], &cup[b[i] - 1]); } for (i = 0; i < n; i++) scanf("%d", &c[i]); for (i = k; i >= x; i--) swap(&c[a[i] - 1], &c[b[i] - 1]); int r1 = -1, r2; for (i = 0; i < n; i++) { if (cup[i] != c[i]) { if (r1 == -1) r1 = i + 1; else { r2 = i + 1; break; } } } printf("%d %d\n", r1, r2); return 0; }