#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main(void) {
  int n, car, in, out, i, max;
  scanf("%d %d", &n, &car);
  max = car;
  for (i = 0; i < n; i++) {
    scanf("%d %d", &in, &out);
    car = car + in - out;
    if (car < 0)
      break;
    if (car > max)
      max = car;
  }
  if (car < 0) {
    printf("0\n");
  } else {
    printf("%d\n", max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b0 <main+0x90>
lea    0xe9d(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    118b <main+0x6b>
jmp    11b0 <main+0x90>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    119d <main+0x7d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11a2 <main+0x82>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <main+0x30>
cmpl   $0x0,-0xc(%rbp)
jge    11cd <main+0xad>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11de <main+0xbe>
mov    -0x1c(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xebd(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1050 <scanf@plt>
mov    (%rsp),%ebx
cmpl   $0x0,0x4(%rsp)
jle    119e <main+0x6e>
xor    %ebp,%ebp
lea    0xe9d(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
add    (%rsp),%eax
sub    0x8(%rsp),%eax
mov    %eax,(%rsp)
js     11b4 <main+0x84>
cmp    %ebx,%eax
cmovg  %eax,%ebx
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1170 <main+0x40>
jmp    11a2 <main+0x72>
test   %ebx,%ebx
js     11b4 <main+0x84>
lea    0xe5d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <main+0x90>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"0\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i32, i32* %3
store i32 %9, i32* %7
store i32 0, i32* %6
br label %10
10: ; preds = %31, %0
%11 = load i32, i32* %6
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %34
14: ; preds = %10
%15 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5)
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = add nsw i32 %16, %17
%19 = load i32, i32* %5
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %14
br label %34
24: ; preds = %14
%25 = load i32, i32* %3
%26 = load i32, i32* %7
%27 = icmp sgt i32 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32, i32* %3
store i32 %29, i32* %7
br label %30
30: ; preds = %28, %24
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %10
34: ; preds = %23, %10
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %42
39: ; preds = %34
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@str = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%10 = load i32, i32* %2
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %0, %23
%14 = phi i32 [ %25, %23 ], [ %10, %0 ]
%15 = phi i32 [ %26, %23 ], [ 0, %0 ]
%16 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %17
%20 = load i32, i32* %4
%21 = sub i32 %19, %20
store i32 %21, i32* %2
%22 = icmp slt i32 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %13
%24 = icmp sgt i32 %21, %14
%25 = select i1 %24, i32 %21, i32 %14
%26 = add nuw nsw i32 %15, 1
%27 = load i32, i32* %1
%28 = icmp slt i32 %26, %27
br i1 %28, label %13, label %33
29: ; preds = %0
%30 = icmp slt i32 %10, 0
br i1 %30, label %31, label %33
31: ; preds = %13, %29
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %36
33: ; preds = %23, %29
%34 = phi i32 [ %10, %29 ], [ %25, %23 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33, %31
ret i32 0
}