fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>()
    for (i 0..answ - 1) a.add(ListOf())
    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 0..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<ArrayList<Int>>(answ, {})
    for (i in 0..answ - 1) a[i].add(-5)
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<ArrayList<Int>>
    for (i in 0..answ - 1) a[i].add(-5)
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = MutableList <ArrayListOf <Int>()>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString(' '))
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<MutableList<Int>>(answ, { i -> mutableListOf() })

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString() + " ")
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 0..a[i].size - 1)
            print (a[i].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<ArrayList<Int>()>(answ)
    for (i in 0..answ - 1) a[i].add(-5)
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>()
    for (i in 0..answ - 1) a.add(ListOf(-5))
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<MutableList<Int>>(answ, { i -> mutableListOf() })

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString(' '))
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>()
    for (i in 0..answ - 1) a.add(ListOf())
    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 0..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>()
    for (i in 0..answ - 1) a[i].add(ListOf(-5))
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 0..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>()
    for (i in 0..answ - 1) a[i].add(-5)
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>()
    for (i in 0..answ - 1) a[i].add(listOf(-5))
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<ArrayList<Int>>()
    for (i in 0..answ - 1) a[i].add(-5)
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = Array<ArrayList<Int>>(answ)
    for (i in 0..answ - 1) a[i].add(-5)
    for (i in 0..n - 1){
        if (a[d].size == 1 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 1 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        for (j in 1..a[i].size - 1)
            print (a[i][j].toString() + ' ')
        println()
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString(' '))
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayListOf <ArrayList <Int>()>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString(' '))
    }
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayList<ArrayList<Int>()>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString(' '))
    }
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toInt() }
    var m = 0
    for (c in a) {
        if (c == -1) m++
    }
    println(m)
    var b = Array<MutableList<Int>>(m, { i -> mutableListOf() })
    var pr = IntArray(m, {i -> if (i > 0) i - 1 else m - 1})
    var ne = IntArray(m, {i -> if (i < m - 1) i + 1 else 0})
    var cur = 0
    for (c in a) {
        if (c == -1) {
            pr[ne[cur]] = pr[cur]
            ne[pr[cur]] = ne[cur]
        } else {
            b[cur].add(c)
        }
        cur = ne[cur]
    }
    var s = Array<String>(m, { i -> "" })
    for (i in 0 until m) {
        s[i] = b[i].size.toString() + " " + b[i].joinToString(" ")
    }
    println(s.joinToString("\n"))
}


fun main(){
    var n = readLine()!!.toInt()
    var arr = readLine()!!.split(' ').map(String::toInt)
    var d : Int = 0
    var answ : Int = 0
    for (x in arr){if (x == -1) answ++}
    var a = ArrayListOf <MutableList <Int>()>(answ)

    for (i in 0..n - 1){
        if (a[d].size == 0 || a[d].size > 0 && a[d].last() != -1){
            a[d].add(arr[i])
        }else{
            d++
            if (d == answ) d = 0
            while (a[d].size != 0 || a[d].size > 0 && a[d].last() == -1){
                d++
                if (d == answ) d = 0
            }
            a[d].add(arr[i])
            d++
            if (d == answ) d = 0
        }
    }
    println(answ)
    for (i in 0..answ - 1){
        print (a[i].size)
        print (" ")
        println (a[i].toString(' '))
    }
}


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) {sc.nextInt()}

    var j  = a.count {
        it == -1
    }

    val lists = ArrayList<ArrayList<Int>>()

    for(i in 0 until j) { lists.add(ArrayList())}

    val availableList = ArrayList(lists)

    var list = 0
    for(i in 0 until m){
        if(a[i] == -1){
            availableList.removeAt(list)
            j--
            list--
        } else {
            availableList[list].add(a[i])
        }

        if(j == 0){
            break
        }

        list = (list + 1) % j
    }

    println(lists.size)

    lists.forEach {
        println("" + it.size + " " + it.joinToString(separator = " "))
    }
}


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) { sc.nextShort() }

    val m1 = (-1).toShort()
    val j  = a.count {
        it == m1
    }

    val lists = ArrayList<ArrayList<Short>>(j)

    for(i in 0 until j) { lists.add(ArrayList(Math.min(m / j, 8000)))}

    val availableList = ArrayList(lists)

    var list = 0
    for(i in 0 until m){
        if(a[i] == m1){
            availableList.removeAt(list)
        } else {
            availableList[list].add(a[i])
            list++
        }

        if(list == availableList.size)
            list = 0
    }

    println(lists.size)

    lists.forEach {
        print(it.size)
        it.forEach {
            print(" $it")
        }
        println()
    }
}


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) {sc.nextInt()}

    var j  = a.count {
        it == -1
    }

    val lists = ArrayList<Pair<Int,ArrayList<Int>>>()

    for(i in 0 until j) { lists.add(Pair(i,ArrayList<Int>()))}

    val finished = ArrayList<Pair<Int,ArrayList<Int>>>()

    var list = 0
    for(i in 0 until m){

        if(a[i] == -1){
            finished.add(lists[list])
            lists.removeAt(list)
            j--
            list--
        } else {
            lists[list].second.add(a[i])
        }

        if(j == 0){
            break
        }

        list = (list + 1) % j
    }

    println(finished.size)

    finished.sortedBy { it.first }.forEach {
        println("" + it.second.size + " " + it.second.joinToString(separator = " "))
    }
}


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) { sc.nextInt() }

    val j  = a.count {
        it == -1
    }

    val lists = ArrayList<ArrayList<Int>>()

    for(i in 0 until j) { lists.add(ArrayList(50000))}

    val availableList = ArrayList(lists)

    var list = 0
    for(i in 0 until m){
        if(a[i] == -1){
            availableList.removeAt(list)
            //j--
            //list--
        } else {
            availableList[list].add(a[i])
            list++
        }

        /*
        if(j == 0){
            break
        }

        list = (list + 1) % j
         */

        if(list == availableList.size)
            list = 0
    }

    println(lists.size)

    lists.forEach {
        print(it.size)
        it.forEach {
            print(" ")
            print(it)
        }
        println()
    }
}


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) { sc.nextInt() }

    val j = a.count {
        it == -1
    }

    val first = Entry(null, null, null, ArrayList())

    var prev = first;
    for (i in 1 until j) {
        prev.next = Entry(prev, null, null, ArrayList())
        prev.nextPrint = prev.next
        prev.next!!.prev = prev
        prev = prev.next!!
    }

    first.prev = prev
    prev.next = first

    var current: Entry? = first

    for (i in 0 until m) {
        if (a[i] == -1) {
            current!!.prev!!.next = current.next
            current!!.next!!.prev = current.prev

            current = current.next!!
        } else {
            current!!.list.add(a[i])
            current = current.next!!
        }

    }

    println(j)

    current = first

    while (current != null) {
        print(current.list.size)
        current.list.forEach {
            print(" $it")
        }
        println()
        current = current.nextPrint
    }
}

data class Entry(var prev: Entry?, var next: Entry?, var nextPrint: Entry?, val list: ArrayList<Int>)


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) { sc.nextInt() }

    val j  = a.count {
        it == -1
    }

    val lists = ArrayList<ArrayList<Int>>()

    for(i in 0 until j) { lists.add(ArrayList(100000))}

    val availableList = ArrayList(lists)

    var list = 0
    for(i in 0 until m){
        if(a[i] == -1){
            availableList.removeAt(list)
            //j--
            //list--
        } else {
            availableList[list].add(a[i])
            list++
        }

        /*
        if(j == 0){
            break
        }

        list = (list + 1) % j
         */

        if(list == availableList.size)
            list = 0
    }

    println(lists.size)

    lists.forEach {
        print(it.size)
        it.forEach {
            print(" ")
            print(it)
        }
        println()
    }
}


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()

    val a = Array(m) { sc.nextInt() }

    val j = a.count {
        it == -1
    }

    val first = Entry(null, null, null, ArrayList(m / j))

    var prev = first;
    for (i in 1 until j) {
        prev.next = Entry(prev, null, null, ArrayList(m / j))
        prev.nextPrint = prev.next
        prev.next!!.prev = prev
        prev = prev.next!!
    }

    first.prev = prev
    prev.next = first

    var current: Entry = first

    for (i in 0 until m) {
        if (a[i] == -1) {
            current.prev!!.next = current.next
            current.next!!.prev = current.prev
        } else {
            current.list.add(a[i])
        }

        current = current.next!!
    }

    println(j)

    var current2: Entry? = first

    while (current2 != null) {
        print(current2.list.size)
        current2.list.forEach {
            print(" $it")
        }
        println()
        current2 = current2.nextPrint
    }
}

data class Entry(var prev: Entry?, var next: Entry?, var nextPrint: Entry?, val list: ArrayList<Int>)


import java.util.*
import kotlin.collections.ArrayList

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val m = sc.nextInt()
    sc.nextLine()

    val s = sc.nextLine()

    /*
    val a = Array(m) {
        sc.nextInt()
    }
     */
/*
    var j  = a.count {
         it == -1
    }
    */

    var a = s.split(' ')

    var j = s.count { it == '-'}

    val lists = ArrayList<ArrayList<String>>()

    for(i in 0 until j) { lists.add(ArrayList())}

    val availableList = ArrayList(lists)

    var list = 0
    for(i in 0 until m){
        if(a[i] == "-1"){
            availableList.removeAt(list)
            j--
            list--
        } else {
            availableList[list].add(a[i])
        }

        if(j == 0){
            break
        }

        list = (list + 1) % j
    }

    println(lists.size)

    lists.forEach {
        print(it.size)
        print(" ")
        it.forEach {
            print(it)
            print(" ")
        }
        println()
        //println("" + it.size + " " + it.joinToString(separator = " "))
    }
}


#include<bits/stdc++.h>

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

int main()
{
    vector<pair<lli, lli> > v;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        lli a, b;
        cin >> a >> b;
        v.push_back({a, b});
    }
    sort(v.begin(), v.end());
    lli ans = 0, cnt = 0;
    for(int i=0; i<v.size(); i++){
        lli fi = v[i].first;
        lli cc = v[i].second;
        lli p=1;
        while(p<cc){
            p *= 4;
            fi++;
        }
        ans = max(ans, fi);
    }
    cout << ans << "\n";

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

int main()
{
    vector<pair<lli, lli> > v;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        lli a, b;
        cin >> a >> b;
        v.push_back({a, b});
    }
    sort(v.begin(), v.end());
    lli ans = 0, cnt = 0;
    for(int i=0; i<v.size(); i++){
        lli fi = v[i].first;
        lli cc = v[i].second;
        lli p=1, pp=0;
        while(pp<cc){
            p *= 4;
            pp = p;
            fi++;
        }
        ans = max(ans, fi);
    }
    cout << ans << "\n";

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

int main()
{
    vector<pair<lli, lli> > v;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        lli a, b;
        cin >> a >> b;
        v.push_back({a, b});
    }
    sort(v.begin(), v.end());
    lli ans = 0, cnt = 0;
    for(int i=0; i<v.size(); i++){
        lli dif = v[i].first-ans;
        if(dif*2 > 66){
            ans = v[i].first;
            if(cnt){
                cnt  = 1;
            }
            else{
                cnt = 0;
            }
            continue;
        }
        bool fl = false;
        for(lli j=0; j<dif*2; j++){
            if(cnt%2) fl = true;

            cnt /= 2;
        }
        cnt += fl;
        cnt = max(cnt, v[i].second);
        ans = v[i].first;
    }
    if(cnt == 1LL){
        cout << ans+1 << "\n";
        return 0;
    }
    while(cnt>1LL){
        bool ck = 0;
        for(int i=0; i<2; i++){
            if(cnt%2) ck = true;
            cnt /= 2;
        }
        cnt += ck;
        ans++;
    }
    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) ((v).begin()),((v).end())
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
double const EPS = 1e-8, PI = acos(-1);
const int N = 3e5 + 9, OO = 1e9;

int main() {
  fastIO;
  int n;
  double ans = 0, a, b;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
//    double cc = ceil((log2(pow(2, a) * pow(2, a) * b)) / 2);
    double cc = ceil(((2 * a + log2(b)) / 2));
    ans = max(ans, cc);
  }
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) ((v).begin()),((v).end())
#define read freopen("input.in", "rt", stdin);
#define write freopen("output.in", "wt", stdout);
#define fastIO cout << fixed << setprecision(0), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
double const EPS = 1e-8, PI = acos(-1);
const int N = 3e5 + 9, OO = 1e9;

int main() {
  fastIO;
  int n;
  ll a, b;
  double ans = 1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
//    double cc = ceil((log2(pow(2, a) * pow(2, a) * b)) / 2);
    double cc = (2*a + (log2(b+(b&1))));
    cc /= 2;
    ans = max(ans, ceil(cc));
  }
  cout << ans;
}


#include<bits/stdc++.h>
using namespace std;

long long int box(long long int n){
    if(n==0){
        return 1;
    }
    else
         return 1+(4*box(n-1));

}

int main(){
   long long  int n,l,r,sum=0,mid,ans,b,flag=1;
    unordered_map<long long int,long long int> umap;
    cin>>n;
    long long int k[n],a[n];
    for(long long int i=0;i<n;i++){
        cin>>k[i]>>a[i];
        umap[k[i]]=a[i];
        sum=sum+a[i];
    }
    sort(k,k+n);
    l=0;
    r=sum+1;
    while(l<=r){

        flag=1;
        mid=l+(r-l)/2;

        b=box(mid);

        if(b<sum){
            l=mid+1;
        }
        if(b>=sum){

            for(long long int i=n-1;i>=0;i--){
                if(pow(2,2*(mid-k[i]))<umap[k[i]]){
                    l=mid+1;
                    flag=0;
                    break;
                }
            }
            if(flag==1){
            ans=mid;
            r=mid-1;
            }

        }
    }
    cout<<ans;
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
    int n; scanf("%d", &n);
	int p = 0, maxk = 0;
	for(int i = 0; i < n; i++) {
		int k, a; scanf("%d %d", &k, &a);
		maxk = max(k, maxk);
		int m = 0, s = 1;
		while(s < a) {
			s *= 4;
			m++;
		}
		p = max(p, k+m);
	}
	if(p == maxk) {
		p++;
	}
	printf("%d\n", p);
}


//............Created by:- Arth Raj...........................//
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<pair<int,int>>
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rlp(i,a,b) for(int i=b;i>=a;i--)
#define ld long double
#define tl tuple<ll,ll,ll>
#define all(x) (x).begin(),(x).end()
#define bs(x,b) binary_search(all(x),b)
#define vip vector<pair<int,pair<int,int>>>
#define pip pair<int,pair<int,int>>
#define INF 1e18
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll abm(ll a, ll b, ll m) {ll ans = 1; a = a % m; while (b > 0) {if (b & 1)ans = (ans * a) % m; a = (a * a) % m; b = b / 2;} return ans % m;}
ll ncr(ll n, ll r, ll m) {if (r == 0)return 1; ll fac[n + 5]; fac[0] = 1; lp(i, 1, n + 1) {fac[i] = fac[i - 1] * i % m;} return (((fac[n] * abm(fac[r], m - 2, m)) % m) * (abm(fac[n - r], m - 2, m))) % m;}
int main()
{
// #ifndef OJ
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n;
	cin >> n;
	vector<pair<ll, ll>> v;
	ll k, a;
	lp(i, 0, n)
	{
		cin >> k >> a;
		v.pb(mp(k, a));
	}
	sort(all(v));
	lp(i, 1, n)
	{
		ll x = v[i].first - v[i - 1].first;
		ll a = 1;
		lp(i, 0, x)
		{
			if ((a * 4) > (1e14))
				break;
			a = a * 4;
		}
		ll boxes = v[i - 1].second / a;
		if ((v[i - 1].second % a) != 0)
			boxes++;
		v[i].second = max(boxes, v[i].second);
	}
	ll ans = v[n - 1].first + 1;
	ll boxes = v[n - 1].second;
	// cout << boxes << endl;
	while (true)
	{
		ll t = boxes / 4;
		if (boxes % 4)
			t++;
		if (t <= 1)
		{
			break;
		}
		else
		{
			ans++;
			boxes = t;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
using namespace std;
const int N=1e5+5;
int lg4(int x){
	int c=(x%4!=0)-1;
	while(x){
		x/=4;
		c++;
	}
	return c;
}

int main() {
	int n,mx=0;cin>>n;
	while(n--){
		int k,a;cin>>k>>a;
		mx=max(lg4(a)+k,mx);
	}
	cout<<mx;
}


#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
using namespace std;
const int N=1e5+5;
int lg4(int x){
	int c=0,t=1;
	while((t<<2) <=x){
		t<<=2;
		c++;
	}
	if(t<x)c++;
	return c;
}

int main() {
	ll n,mx=0,mxs=0;cin>>n;
	while(n--){
		ll k,a;cin>>k>>a;
		mx=max(lg4(a)+k,mx);
		mxs=max(mxs,k);
	}
	cout<<mx + (mxs==mx);
}


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order
//order_of_key

const int maxn = 1e6 + 5;

int n;

map<int,int> mp;
vector<int> v;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  v.resize(n);
  for (int i=0; i<n; i++) {
    int k,a; cin>>k>>a;
    mp[k] = a;
  }

  int i=0;
  for (auto p: mp) {
    v[i++] = p.first;
  }

  for (int i=0; i+1<n; i++) {
    int p1 = v[i];
    int p2 = v[i+1];
    int gap = p2 - p1;
    while (gap > 0 && mp[p1] > 1) {
      --gap;
      mp[p1] = (mp[p1]+3)/4;
    }
    int need = max(0, mp[p1]-mp[p2]);
    mp[p2] += need;
  }

  int ans = v.back();
  int boxes = mp[ans];
  while (boxes > 1) {
    ans++;
    boxes = (boxes+3)/4;
  }
  ans = max(1, ans);
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order
//order_of_key

const int maxn = 1e6 + 5;

int n;

map<int,int> mp;
vector<int> v;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  v.resize(n);
  for (int i=0; i<n; i++) {
    int k,a; cin>>k>>a;
    mp[k] = a;
    v[i] = k;
  }

  for (int i=0; i+1<n; i++) {
    int p1 = v[i];
    int p2 = v[i+1];
    int gap = p2 - p1;
    while (gap > 0 && mp[p1] > 0) {
      --gap;
      mp[p1] = (mp[p1]+3)/4;
    }
    int need = max(0, mp[p1]-mp[p2]);
    mp[p2] += need;
  }

  int ans = v.back();
  int boxes = mp[ans];
  while (boxes > 1) {
    ans++;
    boxes = (boxes+3)/4;
  }
  ans = max(1, ans);
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order
//order_of_key

const int maxn = 1e6 + 5;

int n;

map<int,int> mp;
vector<int> v;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  v.resize(n);
  for (int i=0; i<n; i++) {
    int k,a; cin>>k>>a;
    mp[k] = a;
  }

  int i=0;
  for (auto p: mp) {
    v[i++] = p.first;
  }

  for (int i=0; i+1<n; i++) {
    int p1 = v[i];
    int p2 = v[i+1];
    int gap = p2 - p1;
    while (gap > 0 && mp[p1] > 1) {
      --gap;
      mp[p1] = (mp[p1]+3)/4;
    }
    int need = max(0, mp[p1]-mp[p2]);
    mp[p2] += need;
  }

  int ans = v.back();
  int boxes = mp[ans];
  while (boxes > 4) {
    ans++;
    boxes = (boxes+3)/4;
  }

  ans++;
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order
//order_of_key

const int maxn = 1e6 + 5;

int n;

map<int,int> mp;
vector<int> v;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  v.resize(n);
  for (int i=0; i<n; i++) {
    int k,a; cin>>k>>a;
    mp[k] = a;
    v[i] = k;
  }

  for (int i=0; i+1<n; i++) {
    int p1 = v[i];
    int p2 = v[i+1];
    int gap = p2 - p1;
    while (gap > 0 && mp[p1] > 0) {
      --gap;
      mp[p1] = (mp[p1]+3)/4;
    }
    int need = max(0, mp[p1]-mp[p2]);
    mp[p2] += need;
  }

  int ans = v.back();
  int boxes = mp[ans];
  while (boxes > 1) {
    ans++;
    boxes = (boxes+3)/4;
  }
  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order
//order_of_key

const int maxn = 1e6 + 5;

int n;

map<int,int> mp;
vector<int> v;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  v.resize(n);
  for (int i=0; i<n; i++) {
    int k,a; cin>>k>>a;
    mp[k] = a;
  }

  int i=0;
  for (auto p: mp) {
    v[i++] = p.first;
  }

  for (int i=0; i+1<n; i++) {
    int p1 = v[i];
    int p2 = v[i+1];
    int gap = p2 - p1;
    while (gap > 0 && mp[p1] > 0) {
      --gap;
      mp[p1] = (mp[p1]+3)/4;
    }
    int need = max(0, mp[p1]-mp[p2]);
    mp[p2] += need;
  }

  int ans = v.back();
  int boxes = mp[ans];
  while (boxes > 1) {
    ans++;
    boxes = (boxes+3)/4;
  }
  ans = max(1, ans);
  cout<<ans<<endl;

  return 0;
}


#include<bits\stdc++.h>
using namespace std;

long long n;

int main(){
    cin>>n;
    long long max=-1;
    long long a,k;
    while(n--){
        cin>>k>>a;

        long long temp = ceil(log2(a))-2+k;
        if(temp>max) max=temp;

    }

    if(max<=0) cout<<1;
    else cout<<max;

}


#include<bits\stdc++.h>
using namespace std;

long long n;

int main(){
    cin>>n;
    long long max=-1, max_k=-1;
    long long a,k;
    while(n--){
        cin>>k>>a;
        long long temp ;
        if(a==1) temp = k+1;
        else temp = ceil(log2(a)/2)+k;
        if(temp>max) max=temp;

    }

    if(max<=0) cout<<1;
    else cout<<max;

}


#include<bits\stdc++.h>
using namespace std;

long long n;

int main(){
    cin>>n;
    long long max=-1;
    long long a,k;
    while(n--){
        cin>>k>>a;

        long long temp = ceil(log2(a)/2)+k;
        if(temp>max) max=temp;

    }

    if(max<=0) cout<<1;
    else cout<<max;

}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define fo2(i,a,n) for(ll i=n;i>=a;i--)
#define endl "\n"
#define sp " "
#define f first
#define s second
#define pb push_back
#define buffer ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define init(arr,val) memset(arr,val,sizeof(arr))
#define vecl(v) vector<ll> v
#define vecs(v) vector<string> v
#define vecp(v) vector < pair <ll,ll> > v
#define array_limit 1000010
using namespace std;

int main()
{
    ll n,a,k=0,m,s,p=0,maxk=0;
    cin>>n;
    while(n--)
    {
        cin>>k>>a;
        maxk=(maxk,k);
        s=1,m=0;
        while(s<a)
        {
            s*=4;
            m++;
        }
        p=max(p,k+n);
    }
   if(p==maxk)
    p++;

   cout<<p;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define fo2(i,a,n) for(ll i=n;i>=a;i--)
#define endl "\n"
#define sp " "
#define f first
#define s second
#define pb push_back
#define buffer ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define init(arr,val) memset(arr,val,sizeof(arr))
#define vecl(v) vector<ll> v
#define vecs(v) vector<string> v
#define vecp(v) vector < pair <ll,ll> > v
#define array_limit 1000010
using namespace std;

int main()
{
    ll n,a,k=0,m,s,p=0,maxk=0;
    cin>>n;
    while(n--)
    {
        cin>>k>>a;
        maxk=(maxk,k);
        s=1,m=0;
        while(s<a)
        {
            s*=4;
            m++;
        }
        p=max(maxk,k+m);
    }
   if(p==maxk)
    p+=1;

   cout<<p;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
    std::ios::sync_with_stdio(false); cin.tie(NULL);
 	int n; cin >> n;
	vii a(n);

	for(int i = 0; i < n; i++)
		cin >> a[i].first >> a[i].second;

	sort(all(a));

	int curr = a[0].second;
	int ind = a[0].first;

	for(int i = 1; i < n; i++) {
		while(ind < a[i].first) {
			curr = (curr-1)/4 + 1;
			ind++;
		}
		curr = max(curr, a[i].second);
	}

	while(curr > 4) {
		curr = (curr-1)/4+1;
		ind++;
	}

	ind++;

	cout << ind;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
    std::ios::sync_with_stdio(false); cin.tie(NULL);
 	int n; cin >> n;
	vii a(n);

	for(int i = 0; i < n; i++)
		cin >> a[i].first >> a[i].second;

	sort(all(a));

	ll curr = a[0].second;

	for(int i = 1; i < n; i++) {
		int diff = a[i].first - a[i-1].first;

		if(diff >= 20) curr = 1;
		else curr = (curr-1)/(1ll << (2*diff))+1;

		curr = max(curr, (ll) a[i].second);
	}

	int ind = a[n-1].first;
	while(curr > 4) {
		curr = (curr-1)/4+1;
		ind++;
	}

	ind++;
	cout << ind;

    return 0;
}


#include<bits/stdc++.h>
 using namespace std;

#define  int  long long
#define  endl  '\n'
const int mod = 1e9 + 7;

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int n, ans = 0, k, a;
  cin >> n;

  for(int i = 0; i < n; i++)
  {
    cin >> k >> a;
    while(1)
    {
        a = (a + 3) / 4;
        k++;
        ans = max(ans, k);
        if(a == 1) break;
    }
  }

  cout << ans;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)	( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n;

int main() {
	scanf("%d",&n);
	ll ans = 0;
	loop(i, 0, n - 1) {
		ll k, a;
		scanf("%lld%lld",&k,&a);
		ll lg = log10(a) / log10(4);
		ll p = pow(4, lg);
		if (p != a) lg++;
		ans = max(ans, k + lg);
		if (ans == k) ans++;
	}
	printf("%lld",ans);
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el    '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define all(v)((v).begin()),((v).end())
#define write(v) freopen(v,"w",stdout)
const int N = 1e5 + 74, OO = 0x3f3f3f3f;

int fpow(int x,int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}

pair<int, int> a[N];
class CMagicalBoxes{
public:
    void solve(istream &cin, ostream &cout) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> a[i].first >> a[i].second;
        }
        sort(a,a+n);
        for(int i=1;i<n;i++){
            while(a[i].first - a[i-1].first > 1 && a[i-1].second > 1){
                a[i-1].second = ceil((long double)a[i-1].second / 4);
                if(a[i-1].second == 1)
                    break;
                a[i-1].first++;
            }
        }
        while(true){
            a[n-1].second =  ceil((long double)a[n-1].second / 4);
            if(a[n-1].second == 1)
                break;
            a[n-1].first++;
        }
        cout << a[n-1].first+1 << el;
    }
};

int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	CMagicalBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el    '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define all(v)((v).begin()),((v).end())
#define write(v) freopen(v,"w",stdout)
const int N = 1e5 + 74, OO = 0x3f3f3f3f;

int fpow(int x, int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}

pair<int, int> a[N];

class CMagicalBoxes {
public:
    void solve(istream &cin, ostream &cout) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> a[i].first >> a[i].second;
        }
        sort(a, a + n);
        int i = 1;
        while (i<n) {
            a[i - 1].first++;
            a[i - 1].second = ceil((long double) a[i - 1].second / 4);

            if (a[i - 1].first == a[i].first) {
                if(a[i-1].second > a[i].second)
                    a[i].second += (a[i-1].second - a[i].second);
                i++;
            }else if (a[i - 1].second == 1){
                a[i].second += a[i-1].second;
                i++;
            }
        }
        while (true) {
            a[n - 1].second = ceil((long double) a[n - 1].second / 4);
            a[n - 1].first++;
            if(a[n-1].second == 1)
                break;
        }
        cout << a[n - 1].first<< el;
    }
};

int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	CMagicalBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el    '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define all(v)((v).begin()),((v).end())
#define write(v) freopen(v,"w",stdout)
const int N = 1e5 + 74, OO = 0x3f3f3f3f;

int fpow(int x,int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}

pair<int, int> a[N];
class CMagicalBoxes{
public:
    void solve(istream &cin, ostream &cout) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> a[i].first >> a[i].second;
        }
        sort(a,a+n);
        for(int i=1;i<n;i++){
            while(a[i].first - a[i-1].first > 1 && a[i-1].second > 1){
                a[i-1].first++;
                a[i-1].second = ceil((long double)a[i-1].second / 4);
            }
        }
        while(a[n-1].second > 1){
            a[n-1].first++;
            a[n-1].second =  ceil((long double)a[n-1].second / 4);
        }
        cout << a[n-1].first << el;
    }
};

int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	CMagicalBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el    '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define all(v)((v).begin()),((v).end())
#define write(v) freopen(v,"w",stdout)
const int N = 1e5 + 74, OO = 0x3f3f3f3f;

int fpow(int x, int y) {
    int res = 1;
    while (y > 0) {
        if (y & 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res;
}

pair<int, int> a[N];

class CMagicalBoxes {
public:
    void solve(istream &cin, ostream &cout) {
        int n;
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> a[i].first >> a[i].second;
        }
        sort(a, a + n);
        int i = 1;
        while (i<n) {
            a[i - 1].first++;
            a[i - 1].second = ceil((long double) a[i - 1].second / 4);
            if (a[i - 1].second == 1){
                a[i].second += a[i-1].second;
                i++;
            }else if (a[i - 1].first == a[i].first) {
                if(a[i-1].second > a[i].second)
                    a[i].second += (a[i-1].second - a[i].second);
                i++;
            }
        }
        while (true) {
            a[n - 1].second = ceil((long double) a[n - 1].second / 4);
            a[n - 1].first++;
            if(a[n-1].second == 1)
                break;
        }
        cout << a[n - 1].first<< el;
    }
};

int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	CMagicalBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#pragma warning(disable  4996)
#define _CRT_SECURE_NO_WARNINGS
//#include<bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include<cstring>
#include<map>
#include<set>
#include<string>
#include <climits>
#include <vector>
#include<stack>
#include<bitset>
#include<unordered_map>
#include<queue>
#include<deque>
#include<iomanip>
#define pb push_back
#define endl '\n';
#define sz(s) int(s.size())
#define Ceil(x,y)  ((x+y-1)/y)
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define I64 int
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
const ll mod = ll(1e9 + 7);
const double PI = acos(-1.0);
const int N = (int)1e6;
using namespace std;

void Selim()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int dx[4] = { 0, -1, 0, 1 };
int dy[4] = { -1, 0, 1, 0 };
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll LCM(ll a, ll b) { return a / gcd(a, b)*b; }
//ll fact(long long  n) { return !n ? 1 : n * fact(n - 1); }
//transform(s.begin(), s.end(), s.begin(), ::tolower);
//palindrom if(s==string(s.rbegin(),s.rend()));
//memset(arr,0,sizeof arr)

/*
*********************************************************************************************

If you want something you've never had, you must be willing to do something you've never done

*********************************************************************************************
*/
bool win(string s){
	bool row =
		(s[0] != '.' && s[0] == s[1] && s[1] == s[2] ||
		s[3] != '.' && s[3] == s[4] && s[4] == s[5] ||
		s[6] != '.' && s[6] == s[7] && s[7] == s[8]);
	bool col =
		(s[0] != '.' && s[0] == s[3] && s[3] == s[6] ||
		s[1] != '.' && s[1] == s[4] && s[4] == s[7] ||
		s[2] != '.' && s[2] == s[5] && s[5] == s[8]);
	bool diago =
		(s[0] != '.' && s[0] == s[4] && s[4] == s[8] ||
		s[2] != '.' && s[2] == s[4] && s[4] == s[6]);
	return row || col || diago;
}
string solve(string origen){
	string start = ".........", ans = "no";
	queue<pair<string, bool>>q;
	q.push({ start, 1 });
	while (!q.empty()){
		string cur = q.front().first;
		bool x_OR_o = q.front().second;
		q.pop();
		if (cur == origen){
			ans = "yes";
			break;
		}
		if (!win(cur)){
			for (int i = 0; i < 9; i++){
				if (cur[i] == '.'){
					cur[i] = (x_OR_o ? 'X' : 'O');
					if (cur[i] == origen[i]){
						q.push({ cur, (1 ^ x_OR_o) });
					}
					cur[i] = '.';
				}
			}
		}
	}
	return ans;
}
int main()
{
	Selim();
	int t;
	cin >> t;
	int ans = 0;
	while (t--){
		int k, a;
		cin >> k >> a;
		int cnt = k, NumberOfBoxes = 1;
		while (NumberOfBoxes < a){
			NumberOfBoxes *= 4;
			cnt++;
		}
		if (cnt == k){
			cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define pq priority_queue
#define ext exit(0)
#define ff first
#define ss second
ll n,a[1111111],b[111111],j,i,ans,x,y;

int main () {
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x>>y;
		while(y>1){
			y=(y-1)/4+1;
			x++;
		}
		ans=max(ans,x);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define pq priority_queue
#define ext exit(0)
#define ff first
#define ss second
ll n,a[1111111],b[111111],j,i,ans,x,y;

int main () {
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x>>y;
		if(y==1) x++;
		while(y>1){
			y=(y-1)/4+1;
			x++;
		}
		ans=max(ans,x);
	}
	cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

const long double eps = 1e-12;
const double pi = 3.141592653589793;
const int N = 1e6 + 5;
const int mod  = 1e9 + 7;
const int oo = 2e9 ;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
ll n , k , ans = oo;
pair <ll , ll > t[N];

bool check(int mid){
    k = t[n - 1].fi + 1 ;
    int a = 1;
    while(pow(4,a) < t[n- 1].se) a++ , k++;
    return mid >= k ;
}

int main(){io;
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    cin >>t[i].fi >>t[i].se;
    sort(t , t + n);
    if(n == 1){
        ans = t[0].fi + 1;
        int a  = 1;
        while(pow(4,a) < t[0].se) a++ , ans++;
        return cout <<ans , 0 ;}
    for(int i = 0 ; i  < n - 1 ;++i ) t[i + 1].se= max(t[i+1].se , (t[i].se+3)/4);
    ll l = 0 , r = 1e9;
    while(l <= r){
        ll mid = (l + r)/2;
        if(check(mid)) ans = min(ans,mid) , r = mid - 1;
        else l = mid + 1;
    }
    cout <<ans ;
}


#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

const long double eps = 1e-12;
const double pi = 3.141592653589793;
const int N = 1e6 + 5;
const int mod  = 1e9 + 7;
const int oo = 2e9 ;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
ll n , k , ans = 1e18;
pair <ll , ll > t[N];

bool check(ll mid){
    k = t[n - 1].fi + 1 ;
    ll a = 1;
    while((ll)pow(4,a) < t[n- 1].se) a++ , k++;
    return mid >= k ;
}

int main(){io;
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    cin >>t[i].fi >>t[i].se;
    sort(t , t + n);
    if(n == 1){
        ans = t[0].fi + 1;
        int a  = 1;
        while((ll)pow(4,a) < t[0].se) a++ , ans++;
        return cout <<ans , 0 ;
    }
    for(int i = 0 ; i  < n - 1 ;++i ){
        ll a = 1 , k = 1;
        while(pow(4,a) < t[i].se) a++ ;
         t[i + 1].se = max(t[i+1].se,(ll)pow(4,a)/(ll)pow(4,t[i+1].fi-t[i].fi) );
    }

    ll l = 0 , r = 1e18;
    while(l <= r){
        ll mid = (l + r)/2;
        if(check(mid)) ans = min(ans,mid) , r = mid - 1;
        else l = mid + 1;
    }
    cout <<ans ;
}


#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

const long double eps = 1e-12;
const double pi = 3.141592653589793;
const int N = 1e6 + 5;
const int mod  = 1e9 + 7;
const int oo = 2e9 ;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
ll n , k , ans = oo;
pair <ll , ll > t[N];

bool check(int mid){
    k = t[n - 1].fi + 1 ;
    int a = 1;
    while(pow(4,a) < t[n- 1].se) a++ , k++;
    return mid >= k ;
}

int main(){io;
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    cin >>t[i].fi >>t[i].se;
    sort(t , t + n);
    if(n == 1){
        ans = t[0].fi + 1;
        int a  = 1;
        while(pow(4,a) < t[0].se) a++ , ans++;
        return cout <<ans , 0 ;
    }
    for(int i = 0 ; i  < n - 1 ;++i ){
        int a = 1 , k = 1;
        while(pow(4,a) < t[i].se) a++ , k++;
         t[i + 1].se= max(t[i+1].se , (ll)k );
    }

    ll l = 0 , r = 1e9;
    while(l <= r){
        ll mid = (l + r)/2;
        if(check(mid)) ans = min(ans,mid) , r = mid - 1;
        else l = mid + 1;
    }
    cout <<ans ;
}


#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

const long double eps = 1e-12;
const double pi = 3.141592653589793;
const int N = 1e6 + 5;
const int mod  = 1e9 + 7;
const int oo = 2e9 ;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int n , k , ans = oo;
pair <int ,int > t[N];

bool check(int mid){
     for(int i = 0 ; i  < n - 1 ;++i )
        t[i + 1].se= max(t[i+1].se , (t[i].se+3)/4);
    k = t[n - 1].fi + 1 ;
    int a = 1;
    while(pow(4,a) < t[n- 1].se) a++ , k++;
    return mid >= k ;
}

int main(){io;
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    cin >>t[i].fi >>t[i].se;
    sort(t , t + n);

    int l = 0 , r = 1e9;
    while(l <= r){
        int mid = (l + r)/2;
        if(check(mid)) ans = min(ans,mid) , r = mid - 1;
        else l = mid + 1;
    }
    cout <<ans ;
}


#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

const long double eps = 1e-12;
const double pi = 3.141592653589793;
const int N = 1e6 + 5;
const int mod  = 1e9 + 7;
const int oo = 2e9 ;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
ll n , k , ans = oo;
pair <ll , ll > t[N];

bool check(int mid){
    k = t[n - 1].fi + 1 ;
    ll a = 1;
    while((ll)pow(4,a) < t[n- 1].se) a++ , k++;
    return mid >= k ;
}

int main(){io;
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    cin >>t[i].fi >>t[i].se;
    sort(t , t + n);
    if(n == 1){
        ans = t[0].fi + 1;
        int a  = 1;
        while((ll)pow(4,a) < t[0].se) a++ , ans++;
        return cout <<ans , 0 ;
    }
    for(int i = 0 ; i  < n - 1 ;++i ){
        int a = 1 , k = 1;
        while(pow(4,a) < t[i].se) a++ ;
         t[i + 1].se = max(t[i+1].se,(ll)pow(4,a)/(ll)pow(4,t[i+1].fi-t[i].fi) );
    }

    ll l = 0 , r = 1e9;
    while(l <= r){
        ll mid = (l + r)/2;
        if(check(mid)) ans = min(ans,mid) , r = mid - 1;
        else l = mid + 1;
    }
    cout <<ans ;
}


#include <bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second

const long double eps = 1e-12;
const double pi = 3.141592653589793;
const int N = 1e6 + 5;
const int mod  = 1e9 + 7;
const int oo = 2e9 ;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
ll n , k , ans = oo;
pair <ll , ll > t[N];

bool check(int mid){
    k = t[n - 1].fi + 1 ;
    int a = 1;
    while(pow(4,a) < t[n- 1].se) a++ , k++;
    return mid >= k ;
}

int main(){io;
    cin >>n;
    for(int i = 0 ; i < n ;i++)
    cin >>t[i].fi >>t[i].se;
    sort(t , t + n);
    if(n == 1){
        ans = t[0].fi + 1;
        int a  = 1;
        while(pow(4,a) < t[0].se) a++ , ans++;
        return cout <<ans , 0 ;
    }
    for(int i = 0 ; i  < n - 1 ;++i ){
        int a = 1 , k = 1;
        while(pow(4,a) < t[i].se) a++ ;
         t[i + 1].se = max(t[i+1].se,(ll)(pow(4,a)+ 3)/4 );
    }

    ll l = 0 , r = 1e9;
    while(l <= r){
        ll mid = (l + r)/2;
        if(check(mid)) ans = min(ans,mid) , r = mid - 1;
        else l = mid + 1;
    }
    cout <<ans ;
}


#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define vi vector<int>
#define LLMAX 4000000000000000000LL
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
struct edge
{
	int t, f, w;
	bool operator < (const edge& e) const
	{
		return w > e.w;
	}
	edge(int from, int to, int weight)
	{
		t = to;
		f = from;
		w = weight;
	}
};
#define pll pair<ll,ll>
#define ii pair<int,int>
#define MOD 1000000007
const double EPS = (1e-5);
struct line { double a, b, c; };
struct point {
	double x, y;
	point() { x = y = 0.0; }
	point(double _x, double _y) : x(_x), y(_y) {}
	// use EPS (1e-9) when testing equality of two floating points
	bool operator == (point other) const {
		return (fabs(x - other.x) < EPS && (fabs(y - other.y) < EPS));
	}
};
double dist(point p1, point p2) { // Euclidean distance
// hypot(dx, dy) returns sqrt(dx * dx + dy * dy)
	return fabs(p1.x - p2.x) * fabs(p1.x - p2.x) + fabs(p1.y - p2.y) * fabs(p1.y - p2.y);
}
void pointsToLine(point p1, point p2, line& l) {
	if (fabs(p1.x - p2.x) < EPS) { // vertical line is fine
		l.a = 1.0; l.b = 0.0; l.c = -p1.x; // default values
	}
	else {
		l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);
		l.b = 1.0; // IMPORTANT: we fix the value of b to 1.0
		l.c = -(double)(l.a * p1.x) - p1.y;
	}
}
bool areParallel(line l1, line l2) { // check coefficients a & b
	return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS);
}
bool areSame(line l1, line l2) { // also check coefficient c
	return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS);
}
// returns true (+ intersection point) if two lines are intersect
bool areIntersect(line l1, line l2, point& p) {
	if (areParallel(l1, l2)) return false; // no intersection
	// solve system of 2 linear algebraic equations with 2 unknowns
	p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);
	// special case: test for vertical line to avoid division by zero
	if (fabs(l1.b) > EPS) p.y = -(l1.a * p.x + l1.c);
	else p.y = -(l2.a * p.x + l2.c);
	return true;
}
long long binpowmod(long long a, long long b, long long m){a %= m;long long res = 1;while (b > 0){if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
long long binpow(long long a, long long b){long long res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
int findXOR(int n){switch (n % 4){case 0:return n;case 1:return 1;case 2:return n + 1;case 3:return 0;}}
int rangeXOR(int l, int r){return (findXOR(l - 1) ^ findXOR(r));}
int getbit(int mask, int bit){return (mask & (1 << bit));}void setbit(int& mask, int bit, int val){if (val)mask |= (1 << bit);else mask &= ~(1 << bit);}
//ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
//ll lcm(ll a, ll b){return a * (b / gcd(a, b));}
#define sz(a) int(a.size())
const int N = 1e5+10;
const int M = 2e5+10;
const ll INF = 9999999;
#define PI 3.141592653589793
#define pb push_back
#define all(s) s.begin(),s.end()
#define MOD1 1e8
pair<int,int> a[N];
int n;
bool can(int p)
{
	for (int i = 0; i < n; ++i)
	{
		double have = (p - a[i].first) * log(4);
		double need = log(a[i].second);
		if (need > have)
			return false;
	}
	return true;
}
void solve()
{
	cin >> n;
	int mx = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first >> a[i].second;
		mx = max(mx, a[i].first);
	}
	int lo = mx, hi = 1e9 + 1;
	for (int it = 0; it <= 200; ++it)
	{
		int mid = lo + (hi - lo) >> 1;
		if (can(mid))
		{
			hi = mid;
		}
		else
		{
			lo = mid + 1;
		}
	}
	if (can(lo))
		cout << lo << '\n';
	else
		cout << hi << '\n';
}
int main(void)
{
	//freopen("commandos.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tc = 1;
	//cin >> tc;
	//scanf("%d", &tc);
	while (tc--)
	{
		solve();
		//if (tc)
			//cout << '\n';
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define vi vector<int>
#define LLMAX 4000000000000000000LL
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
struct edge
{
	int t, f, w;
	bool operator < (const edge& e) const
	{
		return w > e.w;
	}
	edge(int from, int to, int weight)
	{
		t = to;
		f = from;
		w = weight;
	}
};
#define pll pair<ll,ll>
#define ii pair<int,int>
#define MOD 1000000007
const double EPS = (1e-5);
struct line { double a, b, c; };
struct point {
	double x, y;
	point() { x = y = 0.0; }
	point(double _x, double _y) : x(_x), y(_y) {}
	// use EPS (1e-9) when testing equality of two floating points
	bool operator == (point other) const {
		return (fabs(x - other.x) < EPS && (fabs(y - other.y) < EPS));
	}
};
double dist(point p1, point p2) { // Euclidean distance
// hypot(dx, dy) returns sqrt(dx * dx + dy * dy)
	return fabs(p1.x - p2.x) * fabs(p1.x - p2.x) + fabs(p1.y - p2.y) * fabs(p1.y - p2.y);
}
void pointsToLine(point p1, point p2, line& l) {
	if (fabs(p1.x - p2.x) < EPS) { // vertical line is fine
		l.a = 1.0; l.b = 0.0; l.c = -p1.x; // default values
	}
	else {
		l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);
		l.b = 1.0; // IMPORTANT: we fix the value of b to 1.0
		l.c = -(double)(l.a * p1.x) - p1.y;
	}
}
bool areParallel(line l1, line l2) { // check coefficients a & b
	return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS);
}
bool areSame(line l1, line l2) { // also check coefficient c
	return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS);
}
// returns true (+ intersection point) if two lines are intersect
bool areIntersect(line l1, line l2, point& p) {
	if (areParallel(l1, l2)) return false; // no intersection
	// solve system of 2 linear algebraic equations with 2 unknowns
	p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);
	// special case: test for vertical line to avoid division by zero
	if (fabs(l1.b) > EPS) p.y = -(l1.a * p.x + l1.c);
	else p.y = -(l2.a * p.x + l2.c);
	return true;
}
long long binpowmod(long long a, long long b, long long m){a %= m;long long res = 1;while (b > 0){if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
long long binpow(long long a, long long b){long long res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
int findXOR(int n){switch (n % 4){case 0:return n;case 1:return 1;case 2:return n + 1;case 3:return 0;}}
int rangeXOR(int l, int r){return (findXOR(l - 1) ^ findXOR(r));}
int getbit(int mask, int bit){return (mask & (1 << bit));}void setbit(int& mask, int bit, int val){if (val)mask |= (1 << bit);else mask &= ~(1 << bit);}
//ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
//ll lcm(ll a, ll b){return a * (b / gcd(a, b));}
#define sz(a) int(a.size())
const int N = 1e5+10;
const int M = 2e5+10;
const ll INF = 9999999;
#define PI 3.141592653589793
#define pb push_back
#define all(s) s.begin(),s.end()
#define MOD1 1e8
pair<int,int> a[N];
int n;

void solve()
{
	cin >> n;
	ll mx = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		ll x, y;
		cin >> x >> y;
		ll m = 0;
		ll v = 1;
		while (v < y)
		{
			v *= 4;
			m++;
		}
		ll s = x + m;
		if (s == x)
			s++;
		mx = max(mx, s);
	}
	cout << mx << '\n';
}
int main(void)
{
	//freopen("commandos.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tc = 1;
	//cin >> tc;
	//scanf("%d", &tc);
	while (tc--)
	{
		solve();
		//if (tc)
			//cout << '\n';
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define vi vector<int>
#define LLMAX 4000000000000000000LL
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
struct edge
{
	int t, f, w;
	bool operator < (const edge& e) const
	{
		return w > e.w;
	}
	edge(int from, int to, int weight)
	{
		t = to;
		f = from;
		w = weight;
	}
};
#define pll pair<ll,ll>
#define ii pair<int,int>
#define MOD 1000000007
const double EPS = (1e-5);
struct line { double a, b, c; };
struct point {
	double x, y;
	point() { x = y = 0.0; }
	point(double _x, double _y) : x(_x), y(_y) {}
	// use EPS (1e-9) when testing equality of two floating points
	bool operator == (point other) const {
		return (fabs(x - other.x) < EPS && (fabs(y - other.y) < EPS));
	}
};
double dist(point p1, point p2) { // Euclidean distance
// hypot(dx, dy) returns sqrt(dx * dx + dy * dy)
	return fabs(p1.x - p2.x) * fabs(p1.x - p2.x) + fabs(p1.y - p2.y) * fabs(p1.y - p2.y);
}
void pointsToLine(point p1, point p2, line& l) {
	if (fabs(p1.x - p2.x) < EPS) { // vertical line is fine
		l.a = 1.0; l.b = 0.0; l.c = -p1.x; // default values
	}
	else {
		l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);
		l.b = 1.0; // IMPORTANT: we fix the value of b to 1.0
		l.c = -(double)(l.a * p1.x) - p1.y;
	}
}
bool areParallel(line l1, line l2) { // check coefficients a & b
	return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS);
}
bool areSame(line l1, line l2) { // also check coefficient c
	return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS);
}
// returns true (+ intersection point) if two lines are intersect
bool areIntersect(line l1, line l2, point& p) {
	if (areParallel(l1, l2)) return false; // no intersection
	// solve system of 2 linear algebraic equations with 2 unknowns
	p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);
	// special case: test for vertical line to avoid division by zero
	if (fabs(l1.b) > EPS) p.y = -(l1.a * p.x + l1.c);
	else p.y = -(l2.a * p.x + l2.c);
	return true;
}
long long binpowmod(long long a, long long b, long long m){a %= m;long long res = 1;while (b > 0){if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
long long binpow(long long a, long long b){long long res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
int findXOR(int n){switch (n % 4){case 0:return n;case 1:return 1;case 2:return n + 1;case 3:return 0;}}
int rangeXOR(int l, int r){return (findXOR(l - 1) ^ findXOR(r));}
int getbit(int mask, int bit){return (mask & (1 << bit));}void setbit(int& mask, int bit, int val){if (val)mask |= (1 << bit);else mask &= ~(1 << bit);}
//ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
//ll lcm(ll a, ll b){return a * (b / gcd(a, b));}
#define sz(a) int(a.size())
const int N = 1e5+10;
const int M = 2e5+10;
const ll INF = 9999999;
#define PI 3.141592653589793
#define pb push_back
#define all(s) s.begin(),s.end()
#define MOD1 1e8
pair<int,int> a[N];
int n;
bool can(int p)
{
	for (int i = 0; i < n; ++i)
	{
		double have = (p - a[i].first) * log(4);
		double need = log(a[i].second);
		if (need > have)
			return false;
	}
	return true;
}
void solve()
{
	cin >> n;
	int mx = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first >> a[i].second;
		mx = max(mx, a[i].first);
	}
	int lo = mx + 1, hi = 1e9 + 1;
	for (int it = 0; it <= 200; ++it)
	{
		int mid = lo + (hi - lo) >> 1;
		if (can(mid))
		{
			hi = mid;
		}
		else
		{
			lo = mid + 1;
		}
	}
	if (can(lo))
		cout << lo << '\n';
	else
		cout << hi << '\n';
}
int main(void)
{
	//freopen("commandos.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tc = 1;
	//cin >> tc;
	//scanf("%d", &tc);
	while (tc--)
	{
		solve();
		//if (tc)
			//cout << '\n';
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef complex<double> point; // 2D point only
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldob;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ii_i;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;

#define re real()
#define im imag()
#define fi first
#define se second

// OST
template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// from: https://codeforces.com/blog/entry/62393
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

const int INF = ~(1<<31);
const ll LINF = (1LL << 60);
const long double EPS = 1e-9;
const long double PI = acos(-1);

const int N = 500005;
const int NN = 1001;
const int MOD = 1e9+7;
const int IMAX = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

ll n, k, p, ans;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0);
	// cout.precision(9); cout << fixed;

	vector<ll> pow4;
	pow4.push_back(4);
	while (pow4.back() <= ll(MOD)*4)
		pow4.push_back(pow4.back()*4);
	cin >> n;
	ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> k >> p;
		ll running = k;
		p = *lower_bound(pow4.begin(), pow4.end(), p);
		while (p > 1) {
			running++;
			p /= 4;
		}
		ans = max(ans, running);
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef complex<double> point; // 2D point only
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldob;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ii_i;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;

#define re real()
#define im imag()
#define fi first
#define se second

// OST
template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// from: https://codeforces.com/blog/entry/62393
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

const int INF = ~(1<<31);
const ll LINF = (1LL << 60);
const long double EPS = 1e-9;
const long double PI = acos(-1);

const int N = 500005;
const int NN = 1001;
const int MOD = 1e9+7;
const int IMAX = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

ll n, k, p, ans;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0);
	// cout.precision(9); cout << fixed;

	vector<ll> pow4;
	pow4.push_back(1);
	while (pow4.back() <= ll(MOD)*4)
		pow4.push_back(pow4.back()*4);
	cin >> n;
	ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> k >> p;
		ll running = k;
		p = *lower_bound(pow4.begin(), pow4.end(), p);
		while (p > 1) {
			running++;
			p /= 4;
		}
		ans = max(ans, running);
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;++i){
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n-1;++i){
        v[i+1].second=max(v[i+1].second,(int)ceil((double)v[i].second/(pow(4,(v[i+1].first-v[i].first)))));
    }
    int q=(ceil((double)log2(v[n-1].second)/2)+v[n-1].first);
    //cout<<ceil((double)log2(v[n-1].second)/2)<<endl;
    if(q==0||q==v[n-1].first)cout<<setprecision(10)<<q+1<<endl;
    else cout<<setprecision(10)<<q<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;++i){
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n-1;++i){
        v[i+1].second=max(v[i+1].second,(int)ceil((double)v[i].second/(pow(4,(v[i+1].first-v[i].first)))));
    }
    int q=(ceil((double)log2(v[n-1].second)/2)+v[n-1].first);
    if(q==0)cout<<setprecision(10)<<q+1<<endl;
    else cout<<setprecision(10)<<q<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;++i){
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n-1;++i){
        v[i+1].second=max(v[i+1].second,(int)ceil((double)v[i].second/(4*(v[i+1].first-v[i].first))));
    }
    cout<<(ceil((double)v[n-1].second/4)+v[n-1].first)<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<pair<int,int>>v(n);
    for(int i=0;i<n;++i){
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n-1;++i){
        v[i+1].second=max(v[i+1].second,(int)ceil((double)v[i].second/(4*(v[i+1].first-v[i].first))));
    }
    int q=(ceil((double)log2(v[n-1].second)/2)+v[n-1].first);
    if(q==0)cout<<setprecision(10)<<q+1<<endl;
    else cout<<setprecision(10)<<q<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;

int n;

ll dp[121111];

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  ll limit = 0;
  for (int i = 0; i < n; i++) {
    ll k, a; cin >> k >> a;
    dp[k] = a;
    limit = max(limit, k);
  }

  for (int i = 0; i < 111111; i++) {
    if (i < limit || dp[i] > 1) {
      dp[i+1] = max(dp[i+1], (dp[i]+3)/4);
    }
  }
  ll anw = 0;
  for (int i = 0; i < 11111; i++) {
    if (dp[i]) anw = i;
  }
  cout << anw << endl;

}


#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;

int n;

ll dp[121111];

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  ll limit = 0;
  for (int i = 0; i < n; i++) {
    ll k, a; cin >> k >> a;
    dp[k] = a;
    limit = max(limit, k);
  }

  for (int i = 0; i < 111111; i++) {
    if (i < limit || dp[i] > 1) {
      dp[i+1] = max(dp[i+1], (dp[i]+3)/4);
    }
  }
  ll anw = 0;
  for (int i = 0; i < 11111; i++) {
    if (dp[i]) anw = i;
  }
  cout << max(anw, limit+1) << endl;

}


#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;

int n;

ll dp[121111];

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  ll limit = 0;
  for (int i = 0; i < n; i++) {
    ll k, a; cin >> k >> a;
    dp[k] = a;
    limit = max(limit, k);
  }

  for (int i = 0; i < 111111; i++) {
    if (i < limit || dp[i] > 1) {
      dp[i+1] = max(dp[i+1], (dp[i]+3)/4);
    }
  }
  ll anw = 0;
  for (int i = 0; i < 11111; i++) {
    if (dp[i]) anw = i;
  }
  cout << max(anw, limit) << endl;

}


#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;

int n;

vector<pair<ll, ll>> v;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  ll limit = 0;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    ll k, a; cin >> k >> a;
    v[i] = {k, a};
    limit = max(limit, k);
  }

  sort(all(v));

  for (int i = 0; i < n-1; i++) {
    ll next = v[i].second;
    for (ll j = v[i].first; j < v[i+1].first && next > 1; j++) {
      next = (next+3)/4;
    }
    v[i+1].second = max(v[i+1].second, next);
  }

  ll anw = v[n-1].first;
  ll cnt = v[n-1].second;
  while(cnt > 1) {
    cnt = (cnt+3)/4;
    anw++;
  }

  cout << max(anw, limit+1) << endl;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

const ll maxn = 1e5+5;
map<ll,ll> qMap;
ll n;
ll ans = 0;

bool pos(ll m){
    bool retval = 1;
    for(auto x:qMap){
        ll s = x.ff, q = x.ss;
        ll pmax = 0;
        fo(i,0,62){
            if(p2(i)>=q){
                pmax = i;
                break;
            };
        }
        if(2*m-2*s<pmax)retval=0;
    }

    re retval;
}

void solve()
{
    rd(n);
    fo(i,0,n-1){
        ll s,q; rd(s,q);
        qMap[s]= q;
        ans = max(ans,s+1);
    }
    ll l = 0,r=5e10;

    // fo(i,1,5){
    //     pp(i,pos(i));
    // }
    while(l<r){
        ll m = (l+r)/2;
        if(pos(m))r = m;
        else l = m + 1;
    }
    ans = max(ans,l);
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

void solve()
{
    ll n;rd(n);
    ll ans = 0;
    fo(i,0,n-1){
        ll s,q; rd(s,q);
        ans = max(ans,s+1);
        ll m = 1;
        ll k = s;
        while(m<q){
            k++;
            m*=4;
        }
        ans = max(ans,k);
    }
    pp(ans);

}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

bool apxeq(ld a, ld b, ld absEpsilon = 1e-12,
           ld relEpsilon = 1e-8) {
  // Check if the numbers are really close -- needed when comparing numbers near
  // zero.
  ld diff = abs(a - b);
  if (diff <= absEpsilon)
    return true;
  else return false;
}

void solve()
{
    ll k;rd(k);
    ld ans = 0;
    fo(i,1,k){
        ld s,q; rd(s,q);
        ld y = log(q)/log(2);
        y/=2;
        y+=s;
        ld _ans = (ll)y;
        if(!apxeq(_ans,y))_ans++;
        else if(q==1)ans++;
        ans = max(ans,_ans);
    }
    pp((ll)ans);
}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

bool apxeq(ld a, ld b, ld absEpsilon = 1e-12,
           ld relEpsilon = 1e-8) {
  // Check if the numbers are really close -- needed when comparing numbers near
  // zero.
  ld diff = abs(a - b);
  if (diff <= absEpsilon)
    return true;
  else return false;
}

void solve()
{
    ll k;rd(k);
    ld ans = 1;
    fo(i,1,k){
        ld s,q; rd(s,q);
        ld y = log(q)/log(2);
        y/=2;
        y+=s;
        ld _ans = (ll)y;
        if(!apxeq(_ans,y))_ans++;
        else if(q==1)ans++;
        ans = max(ans,_ans);
    }
    pp((ll)ans);
}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return
#define endl         "\n"

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2)

#define fo(i,a,b)     for(int i = (int)(a); i <= (int)(b); i++)
#define rf(i,a,b)    for(int i = (int)(a); i >= (int)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***

bool apxeq(ld a, ld b, ld absEpsilon = 1e-12,
           ld relEpsilon = 1e-8) {
  // Check if the numbers are really close -- needed when comparing numbers near
  // zero.
  ld diff = abs(a - b);
  if (diff <= absEpsilon)
    return true;
  else return false;
}

void solve()
{
    ll k;rd(k);
    ld ans = 1;
    fo(i,1,k){
        ld s,q; rd(s,q);
        ld y = log(q)/log(2);
        y/=2;
        y+=s;
        ld _ans = (ll)y;
        if(!apxeq(_ans,y))_ans++;
        ans = max(ans,_ans);
    }
    pp((ll)ans);
}

void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

    cout<<"\n";
    return 0;
}