#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 */

/* Variables and functions */
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(void) {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int ball, a, b;
  scanf("%d", &ball);
  int t = 3;
  while (t > 0) {
    scanf("%d %d", &a, &b);
    t--;
    if (ball == a) {
      ball = b;
      continue;
    }
    if (ball == b) {
      ball = a;
      continue;
    }
  }
  printf("%d", ball);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
lea    0xeb1(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
lea    0xea1(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1040 <freopen@plt>
lea    0xe9e(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x3,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11ec <main+0xbc>
lea    0xe78(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    11d0 <main+0xa0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1190 <main+0x60>
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11e7 <main+0xb7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1190 <main+0x60>
jmp    1190 <main+0x60>
mov    -0x8(%rbp),%esi
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
lea    0xebc(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1040 <freopen@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
lea    0xeac(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1040 <freopen@plt>
lea    0xea9(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe93(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%edx
cmp    %eax,%ecx
jne    11ad <main+0x7d>
mov    %edx,0xc(%rsp)
jmp    11b5 <main+0x85>
cmp    %edx,%ecx
jne    11b5 <main+0x85>
mov    %eax,0xc(%rsp)
lea    0xe5d(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%ecx
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%edx
cmp    %eax,%ecx
jne    11e3 <main+0xb3>
mov    %edx,0xc(%rsp)
jmp    11eb <main+0xbb>
cmp    %edx,%ecx
jne    11eb <main+0xbb>
mov    %eax,0xc(%rsp)
lea    0xe27(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%ecx
cmp    %eax,%esi
jne    121b <main+0xeb>
mov    %ecx,0xc(%rsp)
mov    %ecx,%esi
jmp    1225 <main+0xf5>
cmp    %ecx,%esi
jne    1225 <main+0xf5>
mov    %eax,0xc(%rsp)
mov    %eax,%esi
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @stdin
%7 = call i32 @freopen(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), i32 %6)
%8 = load i32, i32* @stdout
%9 = call i32 @freopen(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), i32 %8)
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
store i32 3, i32* %5
br label %11
11: ; preds = %29, %27, %21, %0
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %3, i32* %4)
%16 = load i32, i32* %5
%17 = add nsw i32 %16, -1
store i32 %17, i32* %5
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %11
23: ; preds = %14
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32, i32* %3
store i32 %28, i32* %2
br label %11
29: ; preds = %23
br label %11
30: ; preds = %11
%31 = load i32, i32* %2
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [11 x i8] c"output.txt\00"
@.str.3 = [2 x i8] c"w\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @stdin
%5 = tail call i32 @freopen(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), i32 %4)
%6 = load i32, i32* @stdout
%7 = tail call i32 @freopen(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), i32 %6)
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%12 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %2, i32* %3)
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = icmp eq i32 %13, %14
%16 = load i32, i32* %3
br i1 %15, label %17, label %41
17: ; preds = %0
store i32 %16, i32* %1
br label %18
18: ; preds = %17, %43, %41
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %2, i32* %3)
%20 = load i32, i32* %1
%21 = load i32, i32* %2
%22 = icmp eq i32 %20, %21
%23 = load i32, i32* %3
br i1 %22, label %27, label %24
24: ; preds = %18
%25 = icmp eq i32 %20, %23
br i1 %25, label %26, label %28
26: ; preds = %24
store i32 %21, i32* %1
br label %28
27: ; preds = %18
store i32 %23, i32* %1
br label %28
28: ; preds = %27, %26, %24
%29 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %2, i32* %3)
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = icmp eq i32 %30, %31
%33 = load i32, i32* %3
br i1 %32, label %37, label %34
34: ; preds = %28
%35 = icmp eq i32 %30, %33
br i1 %35, label %36, label %38
36: ; preds = %34
store i32 %31, i32* %1
br label %38
37: ; preds = %28
store i32 %33, i32* %1
br label %38
38: ; preds = %37, %36, %34
%39 = phi i32 [ %33, %37 ], [ %31, %36 ], [ %30, %34 ]
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %39)
ret i32 0
41: ; preds = %0
%42 = icmp eq i32 %13, %16
br i1 %42, label %43, label %18
43: ; preds = %41
store i32 %14, i32* %1
br label %18
}