fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    var current = readLine()!!.trim().toInt()
    var max = current
    repeat(n){
        val (i, o) = readLine()!!.trim().split(' ').map(String::toInt)
        current += i - o
        if (current < 0) max = -1
        else if (max in 0 until current) max = current
    }
    println(if (max >= 0) max else 0)
}
