#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  FILE *in, *out;
  in = fopen("input.txt", "r");
  out = fopen("output.txt", "w");
  int i, N, M, gara[31], x, y, temp;
  fscanf(in, "%d %d", &N, &M);
  printf("%d %d\n", N, M);
  for (i = 1; i <= N; i++) {
    fscanf(in, "%d", &x);
    gara[x] = i;
  }
  for (i = 1; i <= M; i++) {
    fscanf(in, "%d %d", &x, &y);
    temp = gara[y];
    gara[y] = gara[x];
    gara[x] = temp;
  }
  i = 0;
  while (gara[i] != 1)
    i++;
  fprintf(out, "%d", i);
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     1207 <main+0xb7>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
lea    -0xa4(%rbp),%rdx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x1c(%rbp),%ecx
movslq -0xa4(%rbp),%rax
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c3 <main+0x73>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     128c <main+0x13c>
mov    -0x10(%rbp),%rdi
lea    0xdf4(%rip),%rsi
lea    -0xa4(%rbp),%rdx
lea    -0xa8(%rbp),%rcx
mov    $0x0,%al
call   1050 <fscanf@plt>
movslq -0xa8(%rbp),%rax
mov    -0xa0(%rbp,%rax,4),%eax
mov    %eax,-0xac(%rbp)
movslq -0xa4(%rbp),%rax
mov    -0xa0(%rbp,%rax,4),%ecx
movslq -0xa8(%rbp),%rax
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0xac(%rbp),%ecx
movslq -0xa4(%rbp),%rax
mov    %ecx,-0xa0(%rbp,%rax,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120e <main+0xbe>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmpl   $0x1,-0xa0(%rbp,%rax,4)
01
je     12b3 <main+0x163>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1293 <main+0x143>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xd5b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe85(%rip),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11f1 <main+0xa1>
lea    0xe52(%rip),%r15
mov    %rsp,%r12
xor    %ebp,%ebp
nop
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
movslq (%rsp),%rax
mov    %ebp,0x10(%rsp,%rax,4)
cmp    0x8(%rsp),%ebp
jl     11d0 <main+0x80>
cmpl   $0x0,0x4(%rsp)
jle    1245 <main+0xf5>
lea    0xe1a(%rip),%r15
mov    %rsp,%r12
lea    0xc(%rsp),%r13
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1050 <fscanf@plt>
movslq 0xc(%rsp),%rax
mov    0x10(%rsp,%rax,4),%ecx
movslq (%rsp),%rdx
mov    0x10(%rsp,%rdx,4),%esi
mov    %esi,0x10(%rsp,%rax,4)
mov    %ecx,0x10(%rsp,%rdx,4)
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1210 <main+0xc0>
mov    $0xffffffff,%edx
lea    0x10(%rsp),%rax
nop
add    $0x1,%edx
cmpl   $0x1,(%rax)
lea    0x4(%rax),%rax
jne    1250 <main+0x100>
lea    0xdb9(%rip),%rsi
mov    %r14,%rdi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [31 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %2
%14 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %5, i32* %6)
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %15, i32 %16)
store i32 1, i32* %4
br label %18
18: ; preds = %29, %0
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32*, i32** %2
%24 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %8)
%25 = load i32, i32* %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [31 x i32], [31 x i32]* %7, i64 0, i64 %27
store i32 %25, i32* %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %18
32: ; preds = %18
store i32 1, i32* %4
br label %33
33: ; preds = %55, %32
%34 = load i32, i32* %4
%35 = load i32, i32* %6
%36 = icmp sle i32 %34, %35
br i1 %36, label %37, label %58
37: ; preds = %33
%38 = load i32*, i32** %2
%39 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %8, i32* %9)
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [31 x i32], [31 x i32]* %7, i64 0, i64 %41
%43 = load i32, i32* %42
store i32 %43, i32* %10
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [31 x i32], [31 x i32]* %7, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [31 x i32], [31 x i32]* %7, i64 0, i64 %49
store i32 %47, i32* %50
%51 = load i32, i32* %10
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [31 x i32], [31 x i32]* %7, i64 0, i64 %53
store i32 %51, i32* %54
br label %55
55: ; preds = %37
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %33
58: ; preds = %33
store i32 0, i32* %4
br label %59
59: ; preds = %65, %58
%60 = load i32, i32* %4
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [31 x i32], [31 x i32]* %7, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = icmp ne i32 %63, 1
br i1 %64, label %65, label %68
65: ; preds = %59
%66 = load i32, i32* %4
%67 = add nsw i32 %66, 1
store i32 %67, i32* %4
br label %59
68: ; preds = %59
%69 = load i32*, i32** %3
%70 = load i32, i32* %4
%71 = call i32 @fprintf(i32* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %70)
%72 = load i32*, i32** %2
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %3
%75 = call i32 @fclose(i32* %74)
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [6 x i8] c"%d %d\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [31 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast [31 x i32]* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %2)
%14 = load i32, i32* %1
%15 = load i32, i32* %2
%16 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 %15)
%17 = load i32, i32* %1
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %22, %0
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 1
br i1 %21, label %45, label %31
22: ; preds = %0, %22
%23 = phi i32 [ %28, %22 ], [ 1, %0 ]
%24 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [31 x i32], [31 x i32]* %3, i64 0, i64 %26
store i32 %23, i32* %27
%28 = add nuw nsw i32 %23, 1
%29 = load i32, i32* %1
%30 = icmp slt i32 %23, %29
br i1 %30, label %22, label %19
31: ; preds = %19, %31
%32 = phi i32 [ %42, %31 ], [ 1, %19 ]
%33 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [31 x i32], [31 x i32]* %3, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [31 x i32], [31 x i32]* %3, i64 0, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %36
store i32 %37, i32* %40
%42 = add nuw nsw i32 %32, 1
%43 = load i32, i32* %2
%44 = icmp slt i32 %32, %43
br i1 %44, label %31, label %45
45: ; preds = %31, %19
br label %46
46: ; preds = %45, %46
%47 = phi i64 [ %51, %46 ], [ 0, %45 ]
%48 = getelementptr inbounds [31 x i32], [31 x i32]* %3, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 1
%51 = add nuw i64 %47, 1
br i1 %50, label %52, label %46
52: ; preds = %46
%53 = trunc i64 %47 to i32
%54 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %53)
%55 = call i32 @fclose(i32* %6)
%56 = call i32 @fclose(i32* %7)
ret i32 0
}