@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE", "DEPRECATION")
@file:OptIn(ExperimentalStdlibApi::class)

import java.io.PrintWriter
import java.util.StringTokenizer
import kotlin.collections.ArrayDeque
import kotlin.math.*
import kotlin.random.*
import java.util.TreeMap
import java.util.TreeSet
import java.util.PriorityQueue
// import java.util.*

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

@JvmField val reader = INPUT.bufferedReader()
fun readLine(): String? = reader.readLine()
fun readLn() = reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readString() = readStrings(1)[0]
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int = 2) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int = 2) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

// val isLocal = System.getenv("IS_LOCAL_CP") == "true"

@JvmField
val writer = PrintWriter(OUTPUT)

// ----------------------------------------------------------------------------

class UnionFind {

    private val parents = mutableMapOf<Int, Int>()
    private val sizes = mutableMapOf<Int, Int>()

    fun union(a: Int, b: Int) {
        val fa = find(a)
        val fb = find(b)
        if (fa != fb) {
            parents[fa] = fb
            sizes[fb] = (sizes[fb] ?: 1) + (sizes[fa] ?: 1)
        }
    }

    fun find(a: Int): Int {
        fun getOrDefault(value: Int) = parents.getOrDefault(value, value)

        var parent = getOrDefault(a)
        while (parent != getOrDefault(parent)) {
            parents[parent] = getOrDefault(getOrDefault(parent))
            parent = parents[parent]!!
        }
        return parent
    }

    fun connected(a: Int, b: Int): Boolean {
        return find(a) == find(b)
    }

    fun getSize(a: Int): Int {
        return sizes[find(a)] ?: 1
    }
}

class UnionFindArray(private val n: Int) {

    private val parents = IntArray(n + 1) { it }

    fun union(a: Int, b: Int) {
        val fa = find(a)
        val fb = find(b)
        if (fa != fb) {
            parents[fa] = fb
        }
    }

    fun find(a: Int): Int {
        var parent = parents[a]
        while (parent != parents[parent]) {
            parents[parent] = parents[parents[parent]]
            parent = parents[parent]
        }
        return parent
    }

    fun connected(a: Int, b: Int): Boolean {
        return find(a) == find(b)
    }
}

class Trie() {

    /** Initialize your data structure here. */
    private val root = Node()

    /** Inserts a word into the trie. */
    fun insert(word: String) {
        var node = root
        for (char in word) {
            if (!node.children.contains(char)) {
                node.children[char] = Node()
            }
            node = node.children[char]!!
        }
        node.hasWord = true
    }

    /** Returns if the word is in the trie. */
    fun search(word: String): Boolean {
        return findNode(word)?.hasWord ?: false
    }

    /** Returns if there is any word in the trie that starts with the given prefix. */
    fun startsWith(prefix: String): Boolean {
        return findNode(prefix) != null
    }

    private fun findNode(prefix: String): Node? {
        var node = root
        for (char in prefix) {
            node = node.children[char] ?: return null
        }
        return node
    }

    private class Node(
        var hasWord: Boolean = false,
        val children: MutableMap<Char, Node> = mutableMapOf<Char, Node>()
    )
}

// 所有函数的下标从 0 开始
// query(index): sum[0, index]
class BinaryIndexedTree {

    private val bit: IntArray

    constructor(n: Int) {
        this.bit = IntArray(n + 1)
    }

    constructor(nums: IntArray) {
        this.bit = IntArray(nums.size + 1)
        val prefix = IntArray(bit.size)
        for (i in 1 until nums.size + 1) {
            prefix[i] = prefix[i - 1] + nums[i - 1]
            bit[i] = prefix[i] - prefix[i - lowbit(i)]
        }
    }

    fun query(index: Int): Int {
        var result = 0
        var i = index + 1
        while (i > 0) {
            result += bit[i]
            i -= lowbit(i)
        }
        return result
    }

    fun update(index: Int, x: Int) {
        val value = query(index) - query(index - 1)
        add(index, x - value)
    }

    fun add(index: Int, x: Int) {
        var i = index + 1
        while (i < bit.size) {
            bit[i] += x
            i += lowbit(i)
        }
    }

    override fun toString(): String {
        return IntArray(bit.size - 1) { query(it) - query(it - 1) }.toList().toString()
    }

    private fun lowbit(x: Int): Int {
        return x.and(-x)
    }
}

// 所有函数的下标从 0 开始
// query(index): max[0, index]
// udpate(index, x): 更新 [0, index] 之间的最大值，只能越来越大
class BinaryIndexedTreeMax {

    private val bit: IntArray

    constructor(n: Int) {
        this.bit = IntArray(n + 1)
    }

    fun query(index: Int): Int {
        var result = 0
        var i = index + 1
        while (i > 0) {
            result = Math.max(result, bit[i])
            i -= lowbit(i)
        }
        return result
    }

    fun update(index: Int, x: Int) {
        var i = index + 1
        while (i < bit.size) {
            bit[i] = Math.max(bit[i], x)
            i += lowbit(i)
        }
    }

    private fun lowbit(x: Int): Int {
        return x.and(-x)
    }
}

class SparseTableMax(private val nums: IntArray) {

    private val st: Array<IntArray>

    init {
        val n = nums.size
        val logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))
        this.st = Array(n * 2) { IntArray(logN + 1) }
        for (i in 0 until n) {
            st[i][0] = nums[i]
        }
        for (j in 1 until logN + 1) {
            for (i in 0 until n) {
                st[i][j] = st[i][j - 1]
                if (i + 1.shl(j - 1) < n) {
                    st[i][j] = Math.max(st[i][j], st[i + 1.shl(j - 1)][j - 1])
                }
            }
        }
    }

    fun query(left: Int, right: Int): Int {
        if (left > right) {
            return -1
        }
        val len = right - left + 1
        val k = Integer.numberOfTrailingZeros(Integer.highestOneBit(len))
        return Math.max(st[left][k], st[right - 1.shl(k) + 1][k])
    }
}

class SparseTableMin(private val nums: IntArray) {

    private val st: Array<IntArray>

    init {
        val n = nums.size
        val logN = Integer.numberOfTrailingZeros(Integer.highestOneBit(n))
        this.st = Array(n * 2) { IntArray(logN + 1) { Int.MAX_VALUE / 2 } }
        for (i in 0 until n) {
            st[i][0] = nums[i]
        }
        for (j in 1 until logN + 1) {
            for (i in 0 until n) {
                st[i][j] = st[i][j - 1]
                if (i + 1.shl(j - 1) < n) {
                    st[i][j] = Math.min(st[i][j], st[i + 1.shl(j - 1)][j - 1])
                }
            }
        }
    }

    fun query(left: Int, right: Int): Int {
        if (left > right) {
            return -1
        }
        val len = right - left + 1
        val k = Integer.numberOfTrailingZeros(Integer.highestOneBit(len))
        return Math.min(st[left][k], st[right - 1.shl(k) + 1][k])
    }
}

class PrefixSum2D(private val grid: Array<IntArray>) {

    private val prefix: Array<IntArray>

    init {
        val (m, n) = Pair(grid.size, grid[0].size)
        prefix = Array(m + 1) { IntArray(n + 1) }
        for (i in 0 until m) {
            var row = 0
            for (j in 0 until n) {
                row += grid[i][j]
                prefix[i + 1][j + 1] = prefix[i][j + 1] + row
            }
        }
    }

    fun query(up: Int, left: Int, bottom: Int, right: Int): Int {
        return prefix[up][left] + prefix[bottom + 1][right + 1] -
            prefix[bottom + 1][left] - prefix[up][right + 1]
    }
}

// ----------------------------------------------------------------------------

typealias Graph = Array<MutableList<Int>>

private fun edgesToGraph(n: Int, edges: Array<List<Int>>, directed: Boolean = false): Graph {
    val graph = Array(n) { mutableListOf<Int>() }
    for ((a, b) in edges) {
        graph[a].add(b)
        if (!directed) {
            graph[b].add(a)
        }
    }
    return graph
}

private fun PrintWriter.printNums(nums: List<Int>) {
    if (nums.isEmpty()) {
        println()
        return
    }
    for (i in 0 until nums.size - 1) {
        print(nums[i])
        print(' ')
    }
    println(nums.last())
}

private fun lengthOfLIS(numsInput: List<Int>): Int {
    val nums = unify(numsInput)
    val bit = BinaryIndexedTreeMax(nums.size + 1)
    var result = 0
    for (num in nums) {
        val len = bit.query(num - 1) + 1
        bit.update(num, len)
        result = Math.max(result, len)
    }
    return result
}

private fun unify(nums: List<Int>): List<Int> {
    val numToIndex = nums.sorted().mapIndexed { index, num -> num to index }.toMap()
    return nums.map { numToIndex[it]!! }
}

private fun fastPow(a: Long, exp: Long, mod: Long): Long {
    var result = 1L % mod
    var base = a % mod
    var remain = exp
    while (remain != 0L) {
        if (remain % 2L == 1L) {
            result = (result * base) % mod
        }
        base = (base * base) % mod
        remain /= 2L
    }
    return result
}

private fun gcd(a: Int, b: Int): Int {
    return if (b == 0) a else gcd(b, a % b)
}

private fun gcdL(a: Long, b: Long): Long {
    return if (b == 0L) a else gcdL(b, a % b)
}

private fun lcm(a: Int, b: Int): Int {
    return ((a.toLong() * b.toLong()) / gcd(a, b)).toInt()
}

private fun lcmL(a: Long, b: Long): Long {
    return (a * b) / gcdL(a, b)
}

private fun wordToCharCount(word: String): IntArray {
    val charCount = IntArray(26)
    for (char in word) {
        charCount[char.toIndex()]++
    }
    return charCount
}

private fun Char.toIndex(): Int {
    return this.toInt() - 'a'.toInt()
}

private fun Char.toDigit(): Int {
    return this.toInt() - '0'.toInt()
}

private fun Boolean.toYesNo(upper: Boolean = false): String {
    val yesNo = if (this) "Yes" else "No"
    return if (upper) yesNo.toUpperCase() else yesNo
}

private fun LongArray.modSum(mod: Long = MODL): Long {
    var sum = 0L
    for (num in this) {
        sum = (sum + num) % mod
    }
    return sum
}

private fun IntArray.swap(i: Int, j: Int) {
    val temp = this[i]
    this[i] = this[j]
    this[j] = temp
}

private fun LongArray.swap(i: Int, j: Int) {
    val temp = this[i]
    this[i] = this[j]
    this[j] = temp
}

private fun CharArray.swap(i: Int, j: Int) {
    val temp = this[i]
    this[i] = this[j]
    this[j] = temp
}

private fun <T> List<T>.toArrayDeque(): ArrayDeque<T> {
    return ArrayDeque(this)
}

private fun <T> List<T>.toPair(): Pair<T, T> {
    return Pair(this[0], this[1])
}

private fun <T> List<T>.listEquals(other: List<T>): Boolean {
    return (0 until this.size).all { this[it] == other[it] }
}

private fun <T : Comparable<T>> List<T>.isSorted(): Boolean {
    return this.listEquals(this.sorted())
}

private val DIR = listOf(
    listOf(1, 0), listOf(0, -1), listOf(-1, 0), listOf(0, 1)
)

private const val MOD = 998244353
private const val MODL = 998244353L
// private const val MOD = 1000000007
// private const val MODL = 1000000007L
private const val EPS = 0.000001

// ----------------------------------------------------------------------------

fun main() {
    val go: Runnable = Runnable {
        writer.solve()
        writer.flush()
    }
    Thread(null, go, "thread", 1L.shl(28)).start()
    // writer.solve()
    // writer.flush()
}

private fun PrintWriter.solve() {
    val n = readInt()
    val x = readLong()
    println(requiredLen(n, x))

    // test()
}

private fun test() {
    // println(ULong.MAX_VALUE)
    // println(ULong.MAX_VALUE.toString().length)

    // var num: ULong = 26u
    // while (true) {
    //     val str = num.toString()
    //     val len = str.length
    //     println("$len, $str")
    //     num *= 6u
    //     if (len >= 19) {
    //         break
    //     }
    // }

    val random = Random(12345L)
    repeat(100) {
        // val n = random.nextInt(18) + 2
        // var max = 1L
        // repeat(n - 1) {
        //     max *= 10L
        // }
        // val x = random.nextLong(max - 2L) + 1L
        val n = 10
        val x = random.nextLong(1000L) + 1L

        val r1 = requiredLen(n, x)
        val r2 = requiredLen1(n, x)
        if (r1 != r2) {
            println("$n, $x. $r1, $r2")
        }
    }
}

private fun requiredLen(n: Int, x: Long): Int {
    val queue = listOf(x).toArrayDeque()
    val visited = mutableSetOf<Long>()
    var step = 0
    while (queue.isNotEmpty()) {
        repeat(queue.size) {
            val num = queue.removeFirst()
            if (num < 0L) {
                return step
            }
            if (visited.contains(num)) {
                return@repeat
            }
            visited.add(num)
            val str = num.toString()
            if (str.length == n) {
                return step
            }
            if (str.length > n) {
                return@repeat
            }
            val digits = BooleanArray(10)
            for (char in str) {
                digits[char.toDigit()] = true
            }
            for (d in 2 until 10) {
                if (!digits[d]) {
                    continue
                }
                queue.addLast(num * d)
            }
        }
        step++
        // println(queue)
    }
    return -1
}

// private fun requiredLen(n: Int, x: Long): Int {
//     val MAX = 10000
//     val queue = listOf(x).toArrayDeque()
//     var step = 0
//     while (queue.isNotEmpty()) {
//         val next = mutableListOf<Long>()
//         while (queue.isNotEmpty()) {
//             val num = queue.removeFirst()
//             if (num < 0L) {
//                 return step
//             }
//             val str = num.toString()
//             if (str.length == n) {
//                 return step
//             }
//             if (str.length > n) {
//                 continue
//             }
//             val digits = BooleanArray(10)
//             for (char in str) {
//                 val d = char.toDigit()
//                 if (d <= 1 || digits[d]) {
//                     continue
//                 }
//                 digits[d] = true
//                 next.add(num * d)
//             }
//         }
//         next.sortBy { -it }
//         queue.addAll(next.subList(0, Math.min(MAX, next.size)))
//         step++
//     }
//     return -1
// }

private fun requiredLen1(n: Int, x: Long): Int {
    val queue = listOf(x).toArrayDeque()
    var step = 0
    while (queue.isNotEmpty()) {
        val nextQueue = ArrayDeque<Pair<Long, String>>()
        var maxLen = 0
        while (queue.isNotEmpty()) {
            val num = queue.removeFirst()
            if (num < 0L) {
                return step
            }
            val str = num.toString()
            if (str.length == n) {
                return step
            }
            if (str.length > n) {
                continue
            }
            val digits = BooleanArray(10)
            for (char in str) {
                digits[char.toDigit()] = true
            }
            for (d in 2 until 10) {
                if (!digits[d]) {
                    continue
                }
                val nextNum = num * d
                val nextStr = nextNum.toString()
                nextQueue.addLast(Pair(nextNum, nextStr))
                maxLen = Math.max(maxLen, nextStr.length)
            }
        }
        for ((num, str) in nextQueue) {
            // if (str.length >= maxLen - 3) {
                queue.addLast(num)
            // }
        }
        step++
        // println(queue)
    }
    return -1
}


import java.math.BigInteger
import java.util.*

fun main() {
  val sp = readLine()!!.split(" ")
  val n = sp[0].toInt()
  val x = sp[1].toBigInteger()
  val bfs = LinkedList<State>().apply { add(State(0, x)) }

  val visited = mutableSetOf<BigInteger>()
  while (bfs.isNotEmpty()) {
    val state = bfs.pollFirst()
    val s = state.x.toString().toSet()
    if (state.x.toString().length >= n) {
      println(state.moves)
      return
    }

    for (digit in s) {
      val d = BigInteger((digit - '0').toString())
      val next = state.x.multiply(d)
      if (visited.contains(next)) continue

      bfs.addLast(State(state.moves + 1, next))
      visited.add(next)
    }
  }

  println(-1)
}

data class State(val moves: Int, val x: BigInteger)


fun pow(a: Long, b: Int): Long = if (b == 0) 1 else a * pow(a, b - 1)

fun solve() {
    val line = readLine()!!.split(" ")
    val n = line[0].toInt()
    val x = line[1].toLong()
    val cache = mutableMapOf<Long, Int>()
    fun f(x: Long): Int {
        if (cache.containsKey(x)) {
            return cache[x]!!
        }
        val s = x.toString()
        if (s.length == n) {
            return 0
        }
        var res = -1
        val cands = s.toSet().toList().map { it - '0' }.sorted().reversed()
        for (c in cands) {
            if (c <= 1) {
                continue
            }
            val r = f(x * c) + 1
            if (r > 0 && (res > r || res == -1)) {
                res = r
            }
        }
        cache[x] = res
        return res
    }
    println(f(x))
}

fun main() {
    val t = 1 // readLine()!!.toInt()
    repeat (t) {
        solve()
    }
}


// $time$
import java.io.BufferedInputStream
import java.io.File
import java.io.PrintWriter
import kotlin.system.measureTimeMillis

// 1. Modded
const val p = 1000000007L
const val pI = p.toInt()
fun Int.adjust():Int{ if(this >= pI){ return this  - pI }else if (this < 0){ return this + pI };return this }
fun Int.snap():Int{ if(this >= pI){return this - pI} else return this}
infix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }
infix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }
fun intPow(x:Int,e:Int,m:Int):Int{
    var X = x ; var E =e ; var Y = 1
    while(E > 0){
        if(E and 1 == 0){
            X = ((1L * X * X) % m).toInt()
            E = E shr 1
        }else{
            Y = ((1L * X * Y) % m).toInt()
            E -= 1
        }
    }
    return Y
}
// 2. DP initial values
const val plarge = 1_000_000_727
const val nlarge = -plarge
const val phuge = 2_727_000_000_000_000_000L
const val nhuge = -phuge
// 3. conveniecen conversions
val Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function
val Char.code :Int get() = this.toInt() -  'a'.toInt()
//3. hard to write stuff
fun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }
val mint:MutableList<Int> get() = mutableListOf<Int>()
val mong:MutableList<Long> get() = mutableListOf<Long>()
//4. more outputs
fun List<Char>.conca():String = this.joinToString("")
val CharArray.conca :String get() = this.joinToString("")
val IntArray.conca :String get() = this.joinToString(" ")
@JvmName("concaInt")
fun List<Int>.conca():String = this.joinToString(" ")
val LongArray.conca:String get() = this.joinToString(" ")
@JvmName("concaLong")
fun List<Long>.conca():String = this.joinToString(" ")
//5. Pair of ints
const val longmask = (1L shl 32) - 1
fun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly
val Long.first get() = (this ushr 32).toInt()
val Long.second get() = this.toInt()
//6. strings
val String.size get() = this.length
const val randCount = 100
//7. bits
fun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)
//8 TIME
inline fun TIME(f:()->Unit){
    val t = measureTimeMillis(){
        f()
    }
    println("$t ms")
}
object Reader{
    private const val BS = 1 shl 16
    private const val NC = 0.toChar()
    private val buf = ByteArray(BS)
    private var bId = 0
    private var size = 0
    private var c = NC

    var warningActive = true
    var fakein = StringBuilder()

    private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)
    val OUT: PrintWriter = PrintWriter(System.out)

    private val char: Char
        get() {
            while (bId == size) {
                size = IN.read(buf) // no need for checked exceptions
                if (size == -1) return NC
                bId = 0
            }
            return buf[bId++].toChar()
        }

    fun nextInt(): Int {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }
    fun nextLong(): Long {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0L
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }
    fun nextString():String{
        val ret = StringBuilder()
        while (true){
            c = char
            if(!isWhitespace(c)){ break}
        }
        ret.append(c)
        while (true){
            c = char
            if(isWhitespace(c)){ break}
            ret.append(c)
        }
        return ret.toString()
    }
    fun isWhitespace(c:Char):Boolean{
        return c == ' ' || c == '\n' || c == '\r' || c == '\t'
    }
    fun rerouteInput(){
        if(warningActive){
            put("Custom test enabled")
            println("Custom test enabled")
            warningActive = false
        }
        val S = fakein.toString()
        println("New Case ")
        println(S.take(80))
        println("...")
        fakein.clear()
        IN = BufferedInputStream(S.byteInputStream(),BS)
    }
    fun takeFile(name:String){
        IN = BufferedInputStream(File(name).inputStream(),BS)
    }
}
fun put(aa:Any){ Reader.OUT.println(aa)}
fun done(){ Reader.OUT.close() }
fun share(aa:Any){
    if(aa is IntArray){Reader.fakein.append(aa.joinToString(" "))}
    else if(aa is LongArray){Reader.fakein.append(aa.joinToString(" "))}
    else if(aa is List<*>){Reader.fakein.append(aa.toString())}
    else{Reader.fakein.append(aa.toString())}
    Reader.fakein.append("\n")
}

val getintfast:Int get() = Reader.nextInt()
val getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }
val getlong:Long get() = Reader.nextLong()
val getstr:String get() = Reader.nextString()
fun getline(n:Int):IntArray{
    return IntArray(n){getint}
}
fun getlineL(n:Int):LongArray{
    return LongArray(n){getlong}
}
var dmark = -1
infix fun Any.dei(a:Any){
    dmark++
    var str = "<${dmark}>   "
    debug()
    if(this is String){ str += this
    }else if(this is Int){ str += this.toString()
    }else if(this is Long){ str += this.toString()
    }else{ str += this.toString()}
    if(a is List<*>){ println("$str : ${a.joinToString(" ")}")
    }else if(a is IntArray){ println("$str : ${a.joinToString(" ")}")
    }else if(a is LongArray){ println("$str : ${a.joinToString(" ")}")
    }else if(a is BooleanArray){ println("$str :${a.map{if(it)'1' else '0'}.joinToString(" ")}")
    }else if(a is Array<*>){
        println("$str : ")
        for(c in a){if(c is IntArray){println(c.joinToString(" "))}
        else if(c is LongArray){println(c.joinToString(" "))}
        else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(""))
        }
        }
        println()
    }else{ println("$str : $a")
    }
}
val just = " "
fun crash(){
    throw Exception("Bad programme")}
fun assert(a:Boolean){
    if(!a){
        throw Exception("Failed Assertion")
    }}
enum class solveMode {
    real, rand, tc
}
object solve{
    var mode:solveMode = solveMode.real
    var tcNum:Int = 0
    var rand:()->Unit = {}
    var TC:MutableMap<Int,()->Unit> = mutableMapOf()
    var tn:Long = 0
    fun cases(onecase:()->Unit){
        val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount
        if(pI != 998_244_353 && pI != 1_000_000_007){
            throw Exception("Not usual primes!")
        }
        if(t == 1 && mode != solveMode.real){
            tn = System.currentTimeMillis()
        }
        repeat(t){
            if(mode == solveMode.tc){
                TC[tcNum]?.let { it() }
                Reader.rerouteInput()
            }else if(mode == solveMode.rand){
                rand()
                Reader.rerouteInput()
            }
            onecase()
        }
        if(t == 1 && mode != solveMode.real){
            val dt = System.currentTimeMillis() - tn
            println("Time $dt ms ")
        }
    }
    inline fun singleCase(a:solve.()->Unit){
        val t = if(mode != solveMode.rand){1} else randCount
        repeat(t) { a() }
    }
    fun rand(a:()->Unit){
        this.rand = a
    }
    fun tc(id:Int = 0,a:()->Unit){
        TC[id] = a
    }
    fun usetc(a:Int = 0 ){
        this.tcNum = a
        this.mode = solveMode.tc
    }
    fun userand(){
        this.mode = solveMode.rand
    }
}
fun debug(){}
const val singleCase = true
fun main(){
    solve.cases{

        val n = getint
        val x = getlong
        val Q = ArrayDeque<Pair<Long,Int>> ()
        val tried = mutableSetOf<Long>()
        var target = 1L
        repeat(n-1){
            target *= 10
        }

        Q.add(Pair(x,0))
        while(Q.isNotEmpty()){
            val (v,e) = Q.removeFirst()
//            just dei v
            if(v >= target) {
                put(e)
                return@cases
            }

            for(c in v.toString()){
                val d = c.toInt() - '0'.toInt()
                if(d == 0 || d == 1) continue
                val new = v * d
                if(new in tried) continue
                tried.add(new)
                Q.addLast(Pair(new,e+1))
            }

        }
        put(-1)
        return@cases

    }
    done()
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

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

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

    val z = (n + 1) / 2
    var count = 0
    val a = Array(z) {
        count += 1
        sc.nextInt()
    }
    val b = Array(z) {
        count += 1
        if (count <= n) sc.nextInt()
        else 0
    }

    val A = listFrom(a, m)
    val B = listFrom(b, m)

    var best = Math.max(A.max() ?: 0, B.max() ?: 0)
    A.sortBy { it }
    B.sortBy { -it }

    var cur = 0
    for (i in 0 until A.size) {
        val x = A[i]
        while (cur < B.size && x + B[cur] >= m) {
            cur += 1
        }
        if (cur < B.size) best = Math.max(x + B[cur], best)
    }

    println(best)

}

fun listFrom(a: Array<Int>, m: Int): MutableList<Int> {
    val n = a.size
    var res = mutableListOf<Int>()
    for (s in 0 until (1 shl (n))) {
        var sum = 0
        for(k in 0 until n){
            if ((s shr k) and 1 == 1) sum = (sum + a[k]) % m
        }
        res.add(sum)
    }
    return res

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


import java.io.*
import java.lang.Math.max
import java.util.*

fun main() {
    Solver()
}

class Solver {
    private val io = KotlinIo(System.`in`, System.`out`)

    init {
        val n = io.getLong()
        val m = io.getLong()
        val modNumbers = mutableListOf<Long>()
        for (i in 0 until n) {
            modNumbers.add(io.getLong())
        }
        val meetInTheMiddle = MeetInTheMiddle(modNumbers, m)
        io.println(meetInTheMiddle.getLargestModuloSum())
        io.close()
    }
}

class MeetInTheMiddle(private val numbers: List<Long>, private val moduloValue: Long) {

    private val firstModuloSumList = mutableListOf<Long>()
    private val secondModuloSumList = mutableListOf<Long>()

    fun getLargestModuloSum(): Long {
        val modNumbers = numbers.map { it.rem(moduloValue) }
        if (modNumbers.size == 1) {
            return modNumbers.first()
        }
        val firstList = modNumbers.subList(0, modNumbers.size / 2)
        val secondList = modNumbers.subList(modNumbers.size / 2, modNumbers.size)

        bruteForceModuloSums(0, firstList, firstModuloSumList, firstList.first())
        bruteForceModuloSums(0, firstList, firstModuloSumList, 0L)
        bruteForceModuloSums(0, secondList, secondModuloSumList, secondList.first())
        bruteForceModuloSums(0, secondList, secondModuloSumList, 0L)

        return maxModuloSumBetweenList()
    }

    private fun maxModuloSumBetweenList(): Long {
        val firstModuloSumSet = TreeSet(firstModuloSumList)
        val secondModuloSumSet = TreeSet(secondModuloSumList)
        var maxSum = (firstModuloSumSet.last()).coerceAtLeast(secondModuloSumSet.last())

        firstModuloSumSet.forEach {
            val gap: Long = moduloValue.minus(it+1)
            val floorValue = secondModuloSumSet.floor(gap)
            if (floorValue != null) {
                maxSum = maxSum.coerceAtLeast((it + floorValue).rem(moduloValue))
            }
        }
        return maxSum
    }

    private fun bruteForceModuloSums(index: Int, modNumbers: List<Long>, moduloSumList: MutableList<Long>, sum: Long) {
        if (index == modNumbers.size - 1) {
            moduloSumList.add(sum.rem(moduloValue))
            return
        }
        bruteForceModuloSums(index + 1, modNumbers, moduloSumList, sum + modNumbers[index + 1])
        bruteForceModuloSums(index + 1, modNumbers, moduloSumList, sum)
    }
}

/**
 * IO class with exposing various input operations. Kotlin Translation of
 * [Kattio.java](https://github.com/Kattis/kattio/blob/master/Kattio.java)
 */
class KotlinIo(private val input: InputStream, private val outPut: OutputStream) :
    PrintWriter(BufferedOutputStream(outPut)) {

    private var reader: BufferedReader = BufferedReader(InputStreamReader(input))
    private var line: String? = null
    private var tokenizer: StringTokenizer? = null
    private var token: String? = null

    fun hasMoreTokens() = peekToken() != null

    fun getInt() = nextToken()!!.toInt()

    fun getDouble() = nextToken()!!.toDouble()

    fun getLong() = nextToken()!!.toLong()

    fun getWord() = nextToken()

    fun getLine(): String? {
        try {
            return reader.readLine()
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return null
    }

    private fun peekToken(): String? {
        if (token == null) {
            try {
                while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
                    line = reader.readLine()
                    if (line == null) {
                        return null
                    }
                    tokenizer = StringTokenizer(line)
                }
                token = tokenizer!!.nextToken()
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }
        return token
    }

    private fun nextToken(): String? {
        val ans = peekToken()
        token = null
        return ans
    }
}


import java.io.BufferedReader
import java.util.*

class Solver {

    fun input(inp: FastInputReader) {
        val (n, m, k) = inp.readIntArray(3)
        val a = inp.readIntArray(n)
        for (delta in 1..n) {
            for (mult in -1..1 step 2) {
                val nxt = m - 1 + delta * mult
                if (nxt in 0..n - 1 && a[nxt] in 1..k) {
                    println(delta * 10)
                    return
                }
            }
        }
    }

    fun solve() {

    }

}

object Algorithms {

    tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
    tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

    fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
    fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

}

class FastInputReader {

    private val bufferedReader: BufferedReader = System.`in`.bufferedReader()
    private var stringTokenizer: StringTokenizer = StringTokenizer("")

    fun nextLine(): String = bufferedReader.readLine()
    fun next(): String {
        while (!stringTokenizer.hasMoreTokens())
            stringTokenizer = StringTokenizer(nextLine())
        return stringTokenizer.nextToken()
    }

    fun readInt(): Int = next().toInt()
    fun readLong(): Long = next().toLong()
    fun readDouble(): Double = next().toDouble()

    fun readIntArray(size: Int) = IntArray(size, { readInt() })
    fun readLongArray(size: Int) = LongArray(size, { readLong() })
    fun readStringArray(size: Int) = Array(size, { next() })
    inline fun <reified T> readTArray(size: Int, convert: (Int, String) -> T) = Array(size, { convert(it, next()) })

    fun readIntTable(rows: Int, cols: Int) = Array(rows, { readIntArray(cols) })
    fun readLongTable(rows: Int, cols: Int) = Array(rows, { readLongArray(cols) })
    fun readStringTable(rows: Int, cols: Int) = Array(rows, { readStringArray(cols) })
    inline fun <reified T> readTTable(rows: Int, cols: Int, convert: (Int, Int, String) -> T) = Array(rows, { row -> readTArray(cols, { col, s -> convert(row, col, s) }) })

}

fun main(args: Array<String>) {

//    val millis = measureTimeMillis(Solver()::solve)
//    System.err.println("Time spent: $millis")
    val solver = Solver()
    solver.input(FastInputReader())
    solver.solve()

}


fun main(args: Array<String>) {
    val (n, m, k) = readLine()!!.split(' ').map(String::toInt)
    val arr = readLine()!!.split(' ').map(String::toInt)

    var ans = (n - 1) * 10
    for (i in arr.indices) {
        if (arr[i] > 0 && arr[i] <= k) {
            val d = if (i >= m -1) i - m + 1 else m - 1 - i
            val t = d * 10
            if (t < ans)
                ans = t
        }
    }
    print("$ans\n")
}


import java.util.*
 import kotlin.math.*
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var arr=readLine()!!.split(" ").map{it.toInt()}
        var a=readLine()!!.split(" ").map{it.toInt()}
		var mn=100000
		for(i in a.indices)
		{
		     if(a[i]!=0 && a[i]<=arr[2])
					mn=min(mn,abs(i+1-arr[1])*10)
		}
		print(mn)

}


import kotlin.math.min

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (numHouses, girlHouse, money) = readInts()
    val prices = readInts()
    var minDistance = Int.MAX_VALUE
    for (position in girlHouse until numHouses)
        if (prices[position] in 1..money) {
            minDistance = (position - girlHouse + 1) * 10
            break
        }
    for (position in girlHouse - 2 downTo 0)
        if (prices[position] in 1..money) {
            minDistance = min(minDistance, (girlHouse - 1 - position) * 10)
            break
        }
    print(minDistance)
}


import java.util.*
fun main(args: Array<String>) {
    var sc = Scanner(System.`in`)
    var n = sc.nextInt()
    var a = sc.nextInt()
    val b= IntArray(n+1)
    for (i in 1 ..n )b[i]=sc.nextInt()

    var c =0
    for ( i in 1 ..n){
        if(b[i] == 1 ){
            if (!(2*a-i >= 1 && 2*a-i <= n && b[2*a-i] == 0)) {
                c++
            }
        }
    }

    println(c)
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    var (n, a) = r.readLine()!!.split(" ").map { it.toInt() }
    val v = r.readLine()!!.split(" ").map { it.toInt() }
    val usetime = minOf(a - 1, n - a)
    var ans = 0
    a -= 1
    if (v[a] == 1) ans++
    for (dis in 1..usetime) {
        if (v[a - dis] == 1 && v[a + dis] == 1) ans += 2
    }
    (0..a - usetime - 1).forEach {
        if (v[it] == 1) ans++
    }
    (a + usetime + 1..n - 1).forEach {
        if (v[it] == 1) ans++
    }
    println(ans)
}


import kotlin.math.min

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    var (numCities, policeCity) = readInts()
    policeCity--
    val criminalsPerCity = readInts()
    var sol = criminalsPerCity[policeCity]
    val delta = min(policeCity, numCities - policeCity - 1)
    for (pos in 1 .. delta)
        if (criminalsPerCity[policeCity - pos] + criminalsPerCity[policeCity + pos] == 2) sol += 2
    for (city in 0 until policeCity - delta)
        sol += criminalsPerCity[city]
    for (city in policeCity + 1 + delta until numCities)
        sol += criminalsPerCity[city]
    print(sol)
}


fun main(args: Array<String>) {
    var (n, a) = readLine()!!.split(" ").map(String::toInt)
    val cities : List<Int> = readLine()!!.split(" ").map(String::toInt)
    val ekvidistantniGradovi : MutableList<Pair<Int,Int>> = MutableList(0) {Pair(0,0)}

    a--
    //parova ima min({0..a-1},{a+1..n}) i toliko ih spojim
    val parova = minOf((0 until a).count(),(a + 1 until n).count())
    (1..parova).mapTo(ekvidistantniGradovi) { Pair(cities[a - it], cities[a + it]) } //dodao sam parove

    //preostali "visak" sa lijeve ili desne strane dodam u paru sa -1
    //sto mi oznacava one sto su sigurni, ali nisu upareni
    if((0 until a).count() > (a + 1 until n).count())
        (0 until a-parova).mapTo(ekvidistantniGradovi) { Pair(cities[it], -1)}
    else
        (a+parova+1 until n).mapTo(ekvidistantniGradovi) { Pair(cities[it], -1)}

    var caught = 0
    //na kraju sabiram ako ima oba ili ako ima jedan, a drugi je -1
    ekvidistantniGradovi.forEach {
        if(it.first > 0 && it.second > 0) caught += it.first + it.second
        else if(it.first > 0 && it.second == -1) caught += it.first
    }
    println(caught + cities[a])
}


import java.util.*

fun main() {
    val input = Scanner(System.`in`)
    val stringValue : String = input.nextLine()

    for (index in stringValue.length-1 downTo 0){
        if (stringValue[index].isLetter()){
            when (stringValue[index].toUpperCase()) {
                'A' -> println("YES")
                'E' -> println("YES")
                'I' -> println("YES")
                'O' -> println("YES")
                'U' -> println("YES")
                'Y' -> println("YES")
                else  ->{
                    println("NO")
                }
            }
            return
        }
    }
}


fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readStrings() = readLn().split(" ")
fun readInts() = readStrings().map { it.toInt() }

fun main(args: Array<String>) {
    readLn().apply {
        if (this[indexOfLast { c -> c != '?' && c != ' ' }].toLowerCase() in "aeiouy") print("YES") else print("NO")
    }
}


fun main(args : Array<String>) {
    val link = readLine()!!
    var list: MutableList<Char> = mutableListOf()
    val letters = arrayOf('A','E','I','O','U','Y')

    for (char in link) {
        list.add(char)
    }
    var a = 0
    for(i in list.size-1 downTo 0){
        if(list[i].isLetter()){
            a=i
            break
        }
    }
    var c = 0
    for(i in 0..letters.size-1){
        if(letters[i]==list[a] || letters[i].toLowerCase()==list[a]){
            c++
        }
    }

    if(c!=0){
        println("YES")
    }
    else{
        println("NO")
    }

}


fun main(args: Array<String>) {
    println(if (readLine()!!.toLowerCase().filter { it in ('a'..'z') }.last() in arrayOf('a', 'e', 'i', 'o', 'u', 'y')) "YES" else "NO")
}


fun main() {
    val n = readInt()

    val points = List(4*n + 1) { readInts().let { (x, y) -> Point(x, y) } }

    val xcnt = points.groupingBy { it.x }.eachCount()
    val ycnt = points.groupingBy { it.y }.eachCount()

    fun Map<Int, Int>.squareBoundaries() = run {
        val f = keys.filter {
            this[it]!! >= n
        }
        listOf(f.min()!!, f.max()!!)
    }

    val xb = xcnt.squareBoundaries()
    val yb = ycnt.squareBoundaries()

    val ans = points.first {
        when {
            it.x in xb -> it.y in yb[0]..yb[1]
            it.y in yb -> it.x in xb[0]..xb[1]
            else -> false
        }.not()
    }

    println("${ans.x} ${ans.y}")
}

data class Point(val x: Int, val y: Int)

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readDouble() = readLn().toDouble()
fun readLong() = readLn().toLong()
fun readStrings() = readLn().split(' ')
fun readInts() = readStrings().map { it.toInt() }
fun readDoubles() = readStrings().map { it.toDouble() }
fun readLongs() = readStrings().map { it.toLong() }

class Output {
    private val sb = StringBuilder()
    fun print(o: Any?) { sb.append(o) }
    fun println() { sb.append('\n') }
    fun println(o: Any?) { sb.append(o).append('\n') }
    @JvmName("_print") fun Any?.print() = print(this)
    @JvmName("_println") fun Any?.println() = println(this)
    fun nowPrint() { kotlin.io.print(sb) }
}
inline fun output(block: Output.()->Unit)
    { Output().apply(block).nowPrint() }


fun main() {
    val n = readInt()

    val points = List(4*n + 1) { readInts().let { (x, y) -> Point(x, y) } }

    val xcnt = points.groupingBy { it.x }.eachCount()
    val ycnt = points.groupingBy { it.y }.eachCount()

    fun Map<Int, Int>.squareBoundaries() = run {
        val f = keys.filter {
            this[it]!! >= n
        }
        listOf(f.min()!!, f.max()!!)
    }

    val xb = xcnt.squareBoundaries()
    val yb = ycnt.squareBoundaries()

    val ans = points.first {
        when {
            it.x in xb -> it.y !in yb[0]..yb[1]
            it.y in yb -> it.x !in xb[0]..xb[1]
            else -> true
        }
    }

    println("${ans.x} ${ans.y}")
}

data class Point(val x: Int, val y: Int)

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readDouble() = readLn().toDouble()
fun readLong() = readLn().toLong()
fun readStrings() = readLn().split(' ')
fun readInts() = readStrings().map { it.toInt() }
fun readDoubles() = readStrings().map { it.toDouble() }
fun readLongs() = readStrings().map { it.toLong() }

class Output {
    private val sb = StringBuilder()
    fun print(o: Any?) { sb.append(o) }
    fun println() { sb.append('\n') }
    fun println(o: Any?) { sb.append(o).append('\n') }
    @JvmName("_print") fun Any?.print() = print(this)
    @JvmName("_println") fun Any?.println() = println(this)
    fun nowPrint() { kotlin.io.print(sb) }
}
inline fun output(block: Output.()->Unit)
    { Output().apply(block).nowPrint() }


import java.util.*
import kotlin.collections.*
import kotlin.math.*

val read = Scanner(System.`in`)

fun gcd(a: Long, b: Long): Long{
    return if (a == 0L) b else gcd(b%a, a)
}

fun main(){
    var n: Long = read.nextLong()
    var k: Long = read.nextLong()
    k = Math.pow(10.0, k.toDouble()).toLong()
    print(n * k / gcd(n, k))
}


import java.util.*

fun pow(a: Int, b: Int) = Math.pow(a.toDouble(), b.toDouble()).toLong()
fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val k = scanner.nextInt()
    var n1 = n
    var count2 = 0
    var count5 = 0
    while (n1 % 2 == 0) {
        n1 /= 2
        count2++
    }
    n1 = n
    while (n1 % 5 == 0) {
        n1 /= 5
        count5++
    }
    print(n*(if(k>count2) pow(2, k-count2) else 1) * (if (k > count5) pow(5, k-count5) else 1))
}


// star because
fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (n, k) = readInts()
    var nn = n
    var twos = 0
    var fives = 0
    while(twos < k && nn % 2 == 0) {
        twos++
        nn /= 2
    }
    while(fives < k && nn % 5 == 0) {
        fives++
        nn /= 5
    }
    var sol = n.toLong()
    while (twos < fives) {
        sol *= 2
        twos++
    }
    while (fives < twos) {
        sol *= 5
        fives++
    }
    val sb = StringBuilder(sol.toString())
    for (i in twos until k) sb.append('0')
    print(sb)
}


import java.util.*

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

    val n = sc.nextLong()
    val k = sc.nextInt()

    println(n.round(k))
}

fun Long.round(k: Int): Long {
    var t = this
    var doub = 0
    while (t % 2 == 0L) {
        doub += 1
        t /= 2
    }
    var five = 0
    while (t % 5 == 0L) {
        five += 1
        t /= 5
    }

    var res = this
    while (doub < k) {
        res *= 2
        doub += 1
    }
    while (five < k) {
        res *= 5
        five += 1
    }
    return res
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val (L, R) = na2(N)

    var ans = 0.0

    for (i in 0 until N) {
      for (j in 0 until N) {
        if (i == j) continue
        for (x in L[j] .. R[j]) {
          var prob = 1.0
          for (k in 0 until N) {
            if (k == j) continue

            prob *= if (k == i) {
              val l = max(if (i < j) x else x + 1, L[i])
              val r = R[i]
              max(0, r - l + 1)
            } else {
              val l = L[k]
              val r = min(if (j < k) x else x - 1, R[k])
              max(0, r - l + 1)
            }
          }
          ans += prob * x
        }
      }
    }

    debug{"ans:$ans"}
    for (i in 0 until N) {
      ans /= (R[i] - L[i] + 1)
    }

    out.println("%.10f".format(ans))
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


// https://codeforces.com/problemset/problem/1061/A
fun main() {
    val values = readLine()?.split(' ') ?: return
    if (values.size != 2) {
        return
    }
    var coins = values[0].toInt()
    var remain = values[1].toInt()
    var count = 0
    while (true) {
        if (remain >= coins) {
            remain -= coins
            count++
        } else {
            coins = remain
        }
        if (remain == 0) {
            println(count)
            return
        }
    }

}


fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (n, s) = readInts()
    print (s / n + if (s % n == 0) 0 else 1)
}


fun main(args: Array<String>) {
    solve()
}

private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)

private fun solve() {
    val (n, s) = read().map(String::toInt)

    if(s%n==0){
        println(s/n)
    }else{
        println((s/n)+1)
    }
}


// https://codeforces.com/problemset/problem/1061/A
fun main() {
    val values = readLine()?.split(' ') ?: return
    if (values.size != 2) {
        return
    }
    var coins = values[0].toInt()
    var remain = values[1].toInt()
    var count = 0
    while (true) {
        if (remain >= coins) {
            remain -= coins
            count++
        } else {
            coins-- }
        if (remain == 0) {
            println(count)
            return
        }
    }

}


import kotlin.properties.Delegates
import kotlin.reflect.KProperty

class Memorize<T, R>(val func: (T) -> R) {
    val cache = mutableMapOf<T, R>()

    operator fun getValue(thisRef: Any?, property: KProperty<*>) = { n: T ->
        cache.getOrPut(n) { func(n) }
    }
}

var k by Delegates.notNull<Long>()
var l by Delegates.notNull<Long>()
val f: (Pair<Long, Boolean>) -> Long by Memorize { (weight, hasLeast) ->
    when {
        weight < 0 -> 0
        weight == 0L -> if (hasLeast) 1L else 0L
        hasLeast -> ((1..k).fold(0L) { acc: Long, l: Long -> acc + f(Pair(weight - l, true)) })%1000000007L
        else -> { ((if (k >= l) (l..k).fold(0L) { acc: Long, l: Long ->
                        acc + f(Pair(weight - l, true))
            } else 0L) + (1..minOf(k, l - 1)).fold(0L) { acc: Long, l: Long ->
            acc + f(Pair(weight - l, false)) })%1000000007L
        }
    }//.also { println("weight: $weight hasleast: $hasLeast res: $it") }
}

fun main() {
    val r = System.`in`.bufferedReader()
    //val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    val (weight, kth, least) = r.readLine()!!.split(" ").map { it.toLong() }
    k = kth
    l = least
    println(f(Pair(weight, false))%1000000007L)
    //val n = r.readLine()!!.toInt()
}


fun main(args: Array<String>) {
    var n=0
    var k=0
    var d=0
    val input= readLine()!!.split(" ").map{ it.toInt()}
    n=input[0]
    k=input[1]
    d=input[2]
    var solution=Array(2, {LongArray(n+1, {0})})
    for(i in 1..minOf(n, k)){
        solution[0][i]=if (i<d) 1 else 0
        solution[1][i]=if (i>=d) 1 else 0
    }
    for(i in 2 .. n){
        for(j in 1 .. d-1) {
            if(i-j>=0)
                solution[0][i]=(solution[0][i]+solution[0][i-j])%1000000007
        }
    }
    for(i in 2 .. n){
        for(j in 1 .. d-1) {
            if(i-j>=0)
                solution[1][i]=(solution[1][i]+solution[1][i-j])%1000000007
        }
        for(j in d .. k) {
            if(i-j>=0)
                solution[1][i]=(solution[1][i]+solution[1][i-j]+solution[0][i-j])%1000000007
        }
    }
    println(solution[1][n])
}


import java.io.BufferedReader
import java.io.InputStreamReader

const val MODULO = 1000000007L

fun calc(n: Long, k: Long, d: Long, cache: MutableMap<Triple<Long, Long, Long>, Long>): Long {
    if (n <= 0L) {
        return if (d == 0L && n == 0L) 1L else 0L
    }

    return cache.getOrPut(Triple(n, k, d)) {
        (1..k).map { kIdx -> calc(n-kIdx, k, if (kIdx >= d) 0L else d, cache) }
                .reduce { a, b -> (a + b) % MODULO }
    }
}

fun main() {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val (n, k, d) = reader.readLine().split(' ').map { it.toLong() }

    println(calc(n, k, d, hashMapOf()))
}


import kotlin.math.max
import kotlin.math.min

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val numHolds = readInt()
    val heights = readInts()
    var sol = Int.MAX_VALUE
    for (pos in 1 until numHolds - 1) sol = min(sol, heights[pos + 1] - heights[pos - 1])
    for (pos in 1 until numHolds) sol = max(sol, heights[pos] - heights[pos - 1])
    print(sol)
}


import java.util.*

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

    val n = scanner.nextLine()
    val numbers = scanner.nextLine()

    val arr = numbers.split(' ').map { it.toInt() }.toMutableList()

    var min = Int.MAX_VALUE

    for(i in 1 until arr.size-1) {
        val gap = findMaxGap(arr, i)
        if (gap < min) {
            min = gap
        }
    }

    System.out.print(min)

}

fun findMaxGap(arr: MutableList<Int>, excludePos: Int) : Int {
    val value = arr[excludePos]
    arr.removeAt(excludePos)

//    System.out.println(arr)

    var max = arr[1] - arr[0]
    for(i in 1 until arr.size) {
        if (arr[i] - arr[i-1] > max) {
            max = arr[i] - arr[i-1]
        }
    }

    arr.add(excludePos, value)

    return max
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val lengthArray = readLine()!!.split(" ").asSequence().map { it.toInt() }.toList()

    if (n == 3) {
        println(lengthArray[2] - lengthArray[0])
        return
    }

    var min = lengthArray[1] - lengthArray[0] + lengthArray[2] - lengthArray[1]
    var max = lengthArray[1] - lengthArray[0]

    for (i in 2 until n - 1) {
        val left = lengthArray[i] - lengthArray[i - 1]
        val right = lengthArray[i + 1] - lengthArray[i]

        if (left > max) {
            max = left
        }

        if (right > max) {
            max = right
        }

        if (left + right < min) {
            min = left + right
        }
    }

    println(if (min > max) min else max)
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    val n = r.readLine()!!.toInt()
    val v = r.readLine()!!.split(" ").map { it.toInt() }
    var m = (0..n-2).fold(0){min, i -> if (v[i+1]-v[i]>min) v[i+1]-v[i] else min}
    var min = Int.MAX_VALUE
    (1..n-2).forEach {
        if (v[it+1]-v[it-1]<min) min = v[it+1]-v[it-1]
    }
    println(maxOf(min, m))
}


fun main(vararg args: String) {
    val a = Array(4) { readLine()!!.split(' ').map { it == "1" } }
    val dtp = a.indices.any { a[it][3] && (a[it].subList(0, 3).any { it } || a[(it + 1) % 4][0] || a[(it + 3) % 4][2] || a[(it + 2) % 4][1]) }
    println(if (dtp) "YES" else "NO")
}


fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val lights = Array(4) { IntArray(4) }
    for (pos in 0 until 4) lights[pos] = readInts().toIntArray()
    for (part in 0 until 4) {
        if (lights[part][3] == 1 && (
                    lights[part].sum() > 1 ||
                            lights[(part + 1) % 4][0] == 1 ||
                            lights[(part + 2) % 4][1] == 1 ||
                            lights[(part + 3) % 4][2] == 1)
        ) {
            print("YES")
            return
        }
    }
    print("NO")
}


import java.io.BufferedReader
import java.util.*

class Solver {
    private val inp = FastInputReader()

    fun solve() {
        a.forEachIndexed { i, row ->
            if (row[3] == 1) {
                if (a[(i + 4 - 1) % 4][2] + a[(i + 1) % 4][0] + a[(i + 2) % 4][1] + row.sum() - 1 > 0) {
                    print("YES")
                    return
                }
            }
        }
        print("NO")
    }

    private lateinit var a: Array<IntArray>
    fun input() {
        a = inp.readIntTable(4, 4)
    }
}

object Algorithms {

    tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
    tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

    fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
    fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

}

class FastInputReader {
    private val bufferedReader: BufferedReader = System.`in`.bufferedReader()
    private var stringTokenizer: StringTokenizer = StringTokenizer("")

    fun nextLine(): String = bufferedReader.readLine()
    fun next(): String {
        while (!stringTokenizer.hasMoreTokens())
            stringTokenizer = StringTokenizer(nextLine())
        return stringTokenizer.nextToken()
    }

    fun readInt(): Int = next().toInt()
    fun readLong(): Long = next().toLong()
    fun readDouble(): Double = next().toDouble()

    fun readIntArray(size: Int) = IntArray(size, { readInt() })
    fun readLongArray(size: Int) = LongArray(size, { readLong() })
    fun readStringArray(size: Int) = Array(size, { next() })
    inline fun <reified T> readTArray(size: Int, convert: (Int, String) -> T) = Array(size, { convert(it, next()) })

    fun readIntTable(rows: Int, cols: Int) = Array(rows, { readIntArray(cols) })
    fun readLongTable(rows: Int, cols: Int) = Array(rows, { readLongArray(cols) })
    fun readStringTable(rows: Int, cols: Int) = Array(rows, { readStringArray(cols) })
    inline fun <reified T> readTTable(rows: Int, cols: Int, convert: (Int, Int, String) -> T) = Array(rows, { readTArray(cols, { col, s -> convert(it, col, s) }) })
}

fun main(args: Array<String>) {
//    val millis = measureTimeMillis(Solver()::solve)
//    System.err.println("Time spent: $millis")
    val solver = Solver()
    solver.input()
    solver.solve()
}


import java.util.*

fun main(args: Array<String>) = with(Scanner(System.`in`)){
    val n = nextLong()
    var i = 1
    var lucky = 4L
    while (true) {
        if(n == lucky){
            break
        }
        lucky = increaseLuckyNumber(lucky)
        //println("step: $i, increased: $lucky")
        i++
    }
    println(i)
}

fun increaseLuckyNumber(luck: Long): Long{
    var chars = luck.toString().toCharArray()
    var i = chars.size - 1
    while (true){
        val curr = chars[i]

        if (curr == '4'){
            chars[i] = '7'
            break
        }
        chars[i] = '4'
        if (i == 0){
            var newStr = String(chars)
            newStr = "4$newStr"
            //val newChars = CharArray(chars.size + 1)
            //newChars[0] = '4'
            //newChars.addAll(chars, chars.toCharArray())
            //chars = newChars
            chars = newStr.toCharArray()
            break
        }
        i--
    }
    return String(chars).toLong()
}


import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val list = r.readLine()!!.split(" ").map { it.toInt() }
    //repeat(r.readLine()!!.toInt()) {
    val str = r.readLine()!!
    val len = str.length
    val b = IntArray(len) { if (str[it] == '4') 0 else 1 }
    var ans = 0
    for (i in 0..len-1){
        when(b[i]){
            0 -> ans+=2.0.pow(len-i-1).toInt()
            1 -> ans+=2.0.pow(len-i).toInt()
        }
    }
    println(ans)
    //}
}


import kotlin.math.min

val ones = ArrayList<Long>()

fun lowerBound(n: Long): Int{
    var(lo, hi) = 0 to ones.size - 1
    while(lo < hi){
        val mid = (lo + hi) / 2 + (lo + hi) % 2
        if(ones[mid] < n)
            lo = mid
        else
            hi = mid - 1
    }
    return lo
}

val memo = HashMap<Long, Long>()

fun rec(n: Long): Long{
    if(n in memo)
        return memo[n]!!
    val bs = lowerBound(n)
    if(ones[bs + 1] == n){
        memo[n] = (bs + 2).toLong()
        return (bs + 2).toLong()
    }
    var ans = Long.MAX_VALUE
    if(n - ones[bs] < n)
        ans = min(ans, rec(n - ones[bs]) + bs + 1)
    if(ones[bs + 1] - n < n)
        ans = min(ans, rec(ones[bs + 1] - n) + bs + 2)
    memo[n] = ans
    return ans
}

fun main() {
    val n = readLine()!!.toLong()
    for(i in 1..16)
        ones.add("1".repeat(i).toLong())
    memo[0L] = 0L
    for(i in 1L..6L)
        memo[i] = i
    for(i in 7L..11L)
        memo[i] = 13-i
    println(rec(n))
}


import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {
    val n0 = readLong()

    val M = LongArray(17)
    for(i in 1 until M.size) M[i] = M[i-1] * 10 + 1

    var D = hashMapOf(n0 to 0)

    for(k in M.size-2 downTo 1) {
        if(M[k] > n0) continue

        val Dk = HashMap<Long, Int>()

        for((n, c) in D) {
            Dk.checkMin(n % M[k], c + (n / M[k] * k).toInt())
            val n1 = M[k+1] - n
            Dk.checkMin(n1 % M[k], c + k + 1 + (n1 / M[k] * k).toInt())
        }

        D = Dk
    }

    val ans = D[0]

    println(ans)
}

fun <K> HashMap<K, Int>.checkMin(k: K, v: Int) { if(v < getOrDefault(k, Int.MAX_VALUE)) put(k, v) }

/** IO code start */
@JvmField val _reader = System.`in`.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }

@JvmField val _writer = PrintWriter(System.out, false)
inline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }
fun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks


fun main() {
    var list = readLine()!!.split(' ').map { it.toInt() }

    if (list[0] < list[1]) {
        println(list[0] - 1)
    } else if (list[0]==list[1]) {
        println(list[0]-1)
    } else {

        var ans = list[0] - list[1]
        var sum = list[1]
        for (i in 2..ans) {
            sum += i
        }
        println(sum)
    }
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val len = r.readLine()!!.toInt()
    val (n, k) = r.readLine()!!.split(" ").map { it.toInt() }
    var ans = minOf(k, n-1)
    for (i in 2..n-k){
        ans+=i
    }
    println(ans)
    //val v = r.readLine()!!.split("").filter { it.isNotEmpty() }.map { it.toInt() }.toIntArray()
    /*repeat(r.readLine()!!.toInt()) {
        //val len = r.readLine()!!.toInt()
        val (a, b, c) = r.readLine()!!.split(" ").map { it.toLong() }
        val ans = if (c<a) c else b+c-(b%c)
        println(ans)
    }*/
}


import java.io.BufferedReader
import java.io.InputStreamReader

fun findMin(n: Int, v: Int): Int {
    var cap = 0
    var money = 0
    var rem: Int
    for (i in 1 .. n){
        rem = n - i
        if (cap < rem){
            val missingInTank: Int
            if ((v - cap) <= rem){
                missingInTank = v - cap
            }else{
                missingInTank = rem
            }
            cap += missingInTank
            money += i*missingInTank
        }
        cap--
    }
    return money
}

fun main(args: Array<String>){
    val br = BufferedReader(InputStreamReader(System.`in`))
    val nv = br.readLine().split(" ").map { it.toInt() }
    val n = nv[0]
    val v = nv[1]
    println(findMin(n, v))

}


import java.util.*
import kotlin.collections.HashMap

fun main(args : Array<String>) {
    val input = Scanner(System.`in`)
    var city = HashMap<Int, Int>()

    var j=0
    val n = input.nextInt()
    val u = input.nextInt()
    var sum = u
    if (n < u){
        println(n -1)
    } else {
        for (i in n downTo 1){
            city.put(i, j)
            if (j < u){
                j++
            } else {
                sum += i*1
            }
        }
        println(sum-1)
    }

}


fun main() {
    val s = readLine()!!
    val t = readLine()!!
    if (s.length < t.length) {
        print("need tree")
        return
    }
    val longMap = IntArray(26)
    for (c in s) longMap[c - 'a']++
    for (c in t) {
        if (longMap[c - 'a'] > 0) longMap[c - 'a']-- else {
            print("need tree")
            return
        }
    }
    val automaton = s.length != t.length
    var sPos = 0
    var lPos = 0
    while (sPos < t.length && lPos < s.length) {
        if (t[sPos] == s[lPos]) sPos++
        lPos++
    }
    print(
        when {
            automaton && sPos < t.length -> "both"
            automaton -> "automaton"
            else -> "array"
        }
    )
}


import java.io.*
import java.util.*
import kotlin.math.abs

fun main() {
  val reader = InputReader(try{File("D:/repos/a/input.txt").inputStream()} catch(e: Exception){System.`in`})
  val writer = PrintWriter(try{File("D:/repos/a/output.txt").outputStream()} catch(e: Exception){System.out})

  val x = reader.int()
  val y = reader.int()
  val z = abs(x) + abs(y)
  val ans = when {
    x > 0 && y > 0 -> "0 $z $z 0"
    x < 0 && y < 0 -> "-$z 0 0 -$z"
    x < 0 && y > 0 -> "-$z 0 0 $z"
    else -> "0 -$z $z 0"
  }
  writer.println(ans)

  writer.close()
}

class InputReader(stream: InputStream) {
  private val reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)
  private var tokenizer: StringTokenizer?
  operator fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = try { StringTokenizer(reader.readLine()) }
      catch (e: IOException) { throw RuntimeException(e) }
    }
    return tokenizer!!.nextToken()
  }
  fun ll(): Long { return next().toLong() }
  fun int(): Int { return next().toInt() }
  init { tokenizer = null }
}


import kotlin.math.abs

fun main() {
    var (x, y) = readLine()!!.split(' ').map { it.toInt() }
    var sum = abs(x) + abs(y)
    if (x > 0 && y > 0) {
        println("0 $sum $sum 0")
    } else if (x < 0 && y > 0) {
        println("${-sum} 0 0 ${sum}")
    } else if (x > 0 && y < 0) {
        println("0 ${-sum} ${sum} 0")
    } else {
        println("${-sum} 0 0 ${-sum}")
    }
}


import java.io.*
import java.util.*
import kotlin.math.min

const val INF = 99

fun solve() {

    val a = next().toCharArray().map { it.toInt() - 48 }
    val n = a.size

    var ans = INF
    for (i in 0 until n) {
        for (j in 0 until n) {
            if (i !=j) {
                val x = a[i]
                val y = a[j]
                if ((x*10 + y) % 25 == 0) {
                    val b = a.toMutableList()
                    var count = 0
                    for (k in j+1 until n) {
                        b[k] = b[k-1].also { b[k-1] = b[k] }
                        count++
                    }
                    var l = i
                    if (i < j) {
                       l++
                    }
                    for (k in l until n-1) {
                        b[k] = b[k-1].also { b[k-1] = b[k] }
                        count++
                    }

                    if (b[0] == 0) {
                        count += b.indexOfFirst { it != 0 }
                    }

                    ans = min(ans, count)
                }
            }
        }
    }

    print(if (ans != INF) ans else -1)
}

fun hasNext() : Boolean {
    while (!st.hasMoreTokens()) {
        st = StringTokenizer(input.readLine() ?: return false)
    }
    return true
}

fun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException("No tokens")

fun nextInt() = next().toInt()

fun nextLong() = next().toLong()

fun nextDouble() = next().toDouble()

fun nextLine() = if (hasNext()) st.nextToken("\n")!! else throw RuntimeException("No tokens")

fun nextArray(n : Int) = IntArray(n, { nextInt() })

val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null

var input = when(ONLINE_JUDGE) {
    true -> BufferedReader(InputStreamReader(System.`in`), 32768)
    else -> BufferedReader(FileReader("in.txt"))
}

var output = when(ONLINE_JUDGE) {
    true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))
    else -> PrintWriter(BufferedWriter(FileWriter("out.txt")))
}

var st = StringTokenizer("")

fun main(args: Array<String>) {
    val start = System.currentTimeMillis()
    solve()

    output.close()
    input.close()

    if (!ONLINE_JUDGE) {
        System.err.println("${System.currentTimeMillis() - start} ms")
    }
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.HashSet
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>)
        = Thread { run() }.start()

val scanner = Scanner(System.`in`)
val str = scanner.next()

fun run() {

    if (str.length == 1) {
        println(-1)
        return
    }
    if (str.length == 2) {
        if (Integer.parseInt(str) % 25 == 0)
            println(0)
        else if (Integer.parseInt(str.reversed()) % 25 == 0)
            println(1)
        else
            println(-1)
        return
    }
    var q = 0
    for (i in str)
        if (i == '0')
            q++
    if (q == str.length - 2 && str.length > 3) {
        if (str[str.length - 1] != '0')
            println(2)
        else if (str[str.length - 2] != '0')
            println(1)
        else
            println(0)
        return
    }
    if (q == str.length - 1) {
        println(0)
        return
    }
    var res = Int.MAX_VALUE
    var help = -1
    for (i in str.length - 1 downTo 0) {
        if (str[i] == '0') {
            if (help == -1)
                help = i
            else {
                res = 2 * str.length - 3 - help - i
                break
            }
        }
    }
//    println(res)
    var a = res('2', '5')
//    println(a)
    res = min(res, a)
    a = res('5', '0')
//    println(a)
    res = min(res, a)
    a = res('7', '5')
//    println(a)
    res = min(res, a)
    if (res == Int.MAX_VALUE)
        println(-1)
    else
        println(res)

}

fun res(a: Char, b: Char): Int {
    var help1 = -1
    var help2 = -1
    val l = str.length
//    if (b == '0' && str[0] == '5' && str[1] == '0')
//        return 2 * l - 4
    for (i in str.length - 1 downTo 0) {
        if (str[i] == a) {
            if (help2 != -1) {
                if (i != 0)
                    return 2 * l - 3 - i - help2
                if (b == '0' && str[1] == '0')
                    return 2 * l - 4
                var help = -1
                for (j in 1 until l) {
                    if (str[j] != '0') {
                        help = j
                        break
                    }
                }
                if (help != help2)
                    return 2 * l - 4 - help2 + help
                return 2 * l - 4
            }
            else if (help1 == -1)
                help1 = i
        }
        else if (str[i] == b) {
            if (help1 != -1) {
                if (i != 0)
                    return 2 * l - 2 - i - help1
                var help = -1
                for (j in 1 until l) {
                    if (str[j] != '0') {
                        help = j
                        break
                    }
                }
                if (help != help1)
                    return 2 * l - 3 - help1 + help
                return 2 * l - 3
            }
            else if (help2 == -1)
                help2 = i
        }
    }
    return Int.MAX_VALUE
}

//fun res(a: Char, b: Char): Int {
//    var help1 = -1
//    var help2 = -1
//    for (i in str.length - 1 downTo 0) {
//        if (str[i] == a) {
//            if (help2 != -1) {
//                if (i == 0 && str[1] == '0') {
//                    var help = -1
//                    for (j in 1 until str.length) {
//                        if (str[j] != '0') {
//                            help = j
//                            break
//                        }
//                    }
//                    if (str.substring(1).indexOf(b) == help2) {
//                        if (help2 == str.length - 1)
//                            return Int.MAX_VALUE
//                        return 2 * str.length - 4
//                    }
//                    return str.length - 1 - help2 + help + str.length - 2
//                }
//                return 2 * str.length - 2 - i - help2
//            }
//            else if (help1 != -1)
//                help1 = i
//        }
//        else if (str[i] == b) {
//            if (help1 != -1)
//                return 2 * str.length - 2 - i - help1 + 1
//            else if (help2 != -1)
//                help2 = i
//        }
//    }
//    return Int.MAX_VALUE
//}

//fun run() {
//    val scanner = Scanner(System.`in`)
//    val n = scanner.nextInt()
//    val arr = Array<HashMap<Int, Int>>(n) { HashMap() }
//    val mins = Array<IntArray>(n) { intArrayOf(-1, -1) }
//    val v = IntArray(n) { scanner.nextInt() }
//    val map = HashMap<Int, Int>()
//    var size = 0
//    for (i in v.sorted())
//        if (!map.containsKey(i))
//            map[i] = size++
//    arr.forEach { it[-1] = Int.MAX_VALUE }
//    var res = Int.MAX_VALUE
//    for (i in 0 until n) {
//        val c = scanner.nextInt()
//        val index = map[v[i]]!!
//        for (j in v[i] + 1 until size) {
//            if (arr[j][mins[j][0]]!! > c) {
//                if (mins[j][0] != index)
//                    mins[j][1] = mins[j][0]
//                mins[i][0] = index
//                arr[j][index] = c
//            }
//            else if (map[mins[j][1]]!! > c && mins[j][0] != index) {
//                mins[j][1] = index
//                arr[j][index] = c
//            }
//            res = min(res, arr[j][mins[j][0]]!! + arr[j][mins[j][1]]!! + c)
//        }
//    }
//    println(res)
//}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}
//class Pair(val a: Int, val b: Int)
//class Triple(val a: Int, val b: Int, val c: Int)


import java.io.*
import java.util.*

fun main(args : Array<String>) {
  //====== Input preparations ========================================================
//  val fin = BufferedReader(FileReader("a.in"))
  val fin = BufferedReader(InputStreamReader(System.`in`))
  val fout = PrintWriter (System.out)
  var tokenizer = StringTokenizer("")
  fun next() : String {
    while (!tokenizer.hasMoreTokens())
      tokenizer = StringTokenizer(fin.readLine())
    return tokenizer.nextToken()
  }
  fun nextInt() = next().toInt()
  fun nextPairDec() = nextInt()-1 to nextInt()-1
  //====== Solution below ============================================================
  val lens = arrayOf(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30)
  val toNum = mapOf("monday" to 0, "tuesday" to 1, "wednesday" to 2, "thursday" to 3, "friday" to 4, "saturday" to 5, "sunday" to 6)
  val fst = toNum[next()]!!
  val snd = toNum[next()]!!
  fun solve() : Boolean {
    for (x in lens)
      if ((fst + x) % 7 == snd)
        return true
    return false
  }
  fout.print(if (solve()) "YES" else "NO")
  fout.close()
  fin.close()
}


fun main(args: Array<String>) {
    val  i = listOf("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")
    val l = listOf(0,2,3);
    val a = i.indexOf(readLine())
    val b = i.indexOf(readLine())
    var ok = false;
    l.forEach {
        i -> if ((a + i) % 7 == b) ok = true
    }
    var s = when(ok){
        true -> "Yes"
        else -> "No"
    }
    println(s)
}


import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

private fun String.words() = split(" ")

private fun String.toInts() = split(" ").map { it.toInt() }
private fun String.toLongs() = split(" ").map { it.toLong() }

fun dayToInt(s: String) = when (s) {
    "monday" -> 0
    "tuesday" -> 1
    "wednesday" -> 2
    "thursday" -> 3
    "friday" -> 4
    "saturday" -> 5
    "sunday" -> 6
    else -> throw IllegalArgumentException()
}

private fun solve(input: BufferedReader, output: PrintWriter) {
    val d1 = dayToInt(input.readLine())
    val d2 = dayToInt(input.readLine())

    if (listOf(28, 30, 31).any { (d1 + it) % 7 == d2 })
        output.println("YES") else
        output.println("NO")
}


fun main() {
    val nameToNum = mapOf(
        "monday" to 0, "tuesday" to 1, "wednesday" to 2, "thursday" to 3, "friday" to 4, "saturday" to 5, "sunday" to 6
    )
    val first = nameToNum[readLine()!!]!!
    val second = nameToNum[readLine()!!]!!
    for (diff in listOf(28, 30, 31)) if ((first + diff) % 7 == second) return print("YES")
    print("NO")
}


import java.io.IOException
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    tv()
}

fun tv() {
    val ms = MyScanner()
    val a = ms.nextLong()!!
    val b = ms.nextLong()!!
    val x = ms.nextLong()!!
    val y = ms.nextLong()!!

    var xx = x
    var yy = y

    while (xx != 0L && yy != 0L){
        if (xx > yy){
            xx %= yy
        } else {
            yy %= xx
        }
    }

    val nod = xx + yy
    val xxx = x/ nod
    val yyy = y/nod
    System.out.println(Math.min(a/xxx, b/yyy))

}

internal class MyScanner {
    private val `in` = BufferedReader(InputStreamReader(System.`in`))
    private var buffer: Array<String>? = null
    private var pos = 0

    @Throws(IOException::class)
    fun nextInt(): Int? {
        if (buffer == null) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        if (buffer!!.size <= pos) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        pos++
        return Integer.parseInt(buffer!![pos - 1])
    }

    @Throws(IOException::class)
    fun nextLong(): Long? {
        if (buffer == null) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        if (buffer!!.size <= pos) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        pos++
        return (buffer!![pos - 1]).toLong()
    }

    @Throws(IOException::class)
    fun nextString(): String {
        if (buffer == null) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        if (buffer!!.size <= pos) {
            buffer = `in`.readLine().split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
            pos = 0
        }
        pos++
        return buffer!![pos - 1]
    }

    @Throws(IOException::class)
    fun getIntList(n: Int): List<Int?> {
        val result = mutableListOf<Int?>(n)
        for (i in 0 until n)
            result.add(nextInt())
        return result
    }

    @Throws(IOException::class)
    fun getIntArray(n: Int): IntArray {
        val result = IntArray(n)
        for (i in 0 until n)
            result[i] = nextInt()!!
        return result
    }

}


fun nod(a: Long, b: Long): Long =
        if (a % b != 0L) {
            nod(b, a % b)
        } else {
            b
        }

fun main(args: Array<String>) {
    var (a, b, x, y) = readLine()!!.split(" ").map(String::toLong)

    var nodValue = if (x < y) nod(x, y) else nod(y, x)

    if(nodValue != 1L) {
        x /= nodValue
        y /= nodValue
    }
    println(if (a/x > b/y) b/y else a/x)
}


import java.io.*
import java.util.*
import kotlin.math.min

fun solve() {

    val a = nextLong()
    val b = nextLong()

    var x = nextLong()
    var y = nextLong()

    val d = gcd(x, y)
    x /= d
    y /= d

    val countX = a / x
    val countY = b / y

    println(min(countX, countY))
}

fun gcd(a: Long, b: Long) : Long {
    return if (b == 0L) a else gcd(b, a % b)
}

fun hasNext() : Boolean {
    while (!st.hasMoreTokens()) {
        st = StringTokenizer(input.readLine() ?: return false)
    }
    return true
}

fun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException("No tokens")

fun nextInt() = next().toInt()

fun nextLong() = next().toLong()

fun nextDouble() = next().toDouble()

fun nextLine() = if (hasNext()) st.nextToken("\n")!! else throw RuntimeException("No tokens")

fun nextArray(n : Int) = IntArray(n, { nextInt() })

val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null

var input = when(ONLINE_JUDGE) {
    true -> BufferedReader(InputStreamReader(System.`in`), 32768)
    else -> BufferedReader(FileReader("in.txt"))
}

var output = when(ONLINE_JUDGE) {
    true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))
    else -> PrintWriter(BufferedWriter(FileWriter("out.txt")))
}

var st = StringTokenizer("")

fun main(args: Array<String>) {
    val start = System.currentTimeMillis()
    solve()

    output.close()
    input.close()

/*    if (!ONLINE_JUDGE) {
        System.err.println("${System.currentTimeMillis() - start} ms")
    }*/
}


import java.util.*

fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    fun gcd(x: Long, y: Long):Long = if (y == 0L) x else gcd(y, x % y)

    val a = nextLong()
    val b = nextLong()
    val x = nextLong()
    val y = nextLong()

    val g = gcd(x, y)
    val _x = x / g
    val _y = y / g

    println(Math.min(a / _x, b / _y))
}


import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.max

fun main() {
    val input = BufferedReader(InputStreamReader(System.`in`))
    val rgb = input.readLine().split(' ').map { it.toLong() }.sortedDescending().toLongArray()

    val leftovers = max(0, rgb[0] - rgb[1] * 2 - rgb[2] * 2)
    val result = (rgb.sum() - leftovers) / 3

    println(result)
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val A = na(3).map{it.toLong()}
    val S = A.sum()
    val remain = max(
      max(0, A[0] - 2 * (A[1] + A[2]))
    , max(
        max(0, A[1] - 2 * (A[0] + A[2]))
      , max(0, A[2] - 2 * (A[0] + A[1]))
      )
    )
    out.println((S - remain) / 3)
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n, offset) { ni() }
  }

  private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i + offset)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun <A, B> pair(a: A, b: B) = RPair(a, b)
data class RPair<A, B>(val _1: A, val _2: B)

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.io.*
import java.lang.StringBuilder
import java.util.*
import kotlin.collections.*
import kotlin.math.*

val maxn = 200005
val sz = 256 * 1024
val inf0 = 2e9
val inf = inf0.toInt()
val INF0 = 4e18
val INF = INF0.toLong()
val eps = 1e-6
val MOD = 998244353L

fun solve() {
    var r = nextLong()
    var g = nextLong()
    var b = nextLong()
    val a = LongArray(3)
    a[0] = r
    a[1] = g
    a[2] = b
    a.sort()
    val sum = r + g + b
    if (a[2] >= 2 * (a[0] + a[1])){
        println(a[0] + a[1])
    } else println(sum / 3)
}

val multitest = false

fun main() {
    var t = 1
    if (multitest) t = nextInt()
    for (i in 1..t) solve()
    out.flush()
}

fun max(a : Pair<Long, Long>, b : Pair<Long, Long>) : Pair<Long, Long>{
    if (a.first > b.first) return a
    if (b.first > a.first) return b
    if (a.second > b.second) return a
    return b
}

fun back(a: ArrayList<Int>): Int {
    return a[a.size - 1]
}

val t = IntArray(2 * sz)

fun upd(v: Int, vl: Int, vr: Int, i: Int, x: Int) {
    if (i < vl || i > vr) return
    if (vl == vr) {
        t[v] = x
        return
    }
    val vm = (vl + vr) / 2
    upd(v * 2 + 1, vl, vm, i, x)
    upd(v * 2 + 2, vm + 1, vr, i, x)
    t[v] = max(t[v * 2 + 1], t[v * 2 + 2])
}

fun query(v: Int, vl: Int, vr: Int, l: Int, r: Int): Int {
    if (vl > r || l > vr) return -1
    if (vl >= l && vr <= r) return t[v]
    val vm = (vl + vr) / 2
    return max(query(v * 2 + 1, vl, vm, l, r), query(v * 2 + 2, vm + 1, vr, l, r))
}

val fact = LongArray(maxn)
val invfact = LongArray(maxn)

fun calcFactorials() {
    fact[0] = 1
    for (i in 1..maxn - 1) fact[i] = (fact[i - 1] * i.toLong()) % MOD
    for (i in 0..maxn - 1) invfact[i] = powmod(fact[i], MOD - 2, MOD)
}

fun cnk(n: Int, k: Int, m: Long): Long {
    return ((fact[n] * invfact[k]) % m) * invfact[n - k] % m
}

fun powmod(x: Long, d: Long, m: Long): Long {
    if (d == 0L) return 1
    if (d % 2 == 0L) {
        val y = powmod(x, d / 2, m)
        return (y * y) % m
    }
    return x * powmod(x, d - 1, m) % m
}

fun divup(x: Int, y: Int): Int {
    return (x + y - 1) / y
}

fun divup(x: Long, y: Long): Long {
    return (x + y - 1) / y
}

fun gcd(x: Long, y: Long): Long {
    if (x == 0L || y == 0L) return x + y
    if (x > y) return gcd(x % y, y)
    return gcd(y % x, x)
}

fun end() {
    out.flush()
    System.exit(0)
}

fun printIntArray(a: IntArray) {
    for (x in a) print("$x ")
    print("\n")
}

fun printIntArrayList(a: ArrayList<Int>) {
    for (x in a) print("$x ")
    print("\n")
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()

val reader = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out, false)
var tokenizer = StringTokenizer("")

fun println(o: Any) = out.println(o)
fun print(o: Any) = out.print(o)

fun next(): String {
    while (!tokenizer.hasMoreTokens())
        tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

fun increase(map: HashMap<Int, Int>, k: Int) {
    map[k] = 1 + if (map.containsKey(k)) map[k]!! else 0
}

fun decrease(map: HashMap<Int, Int>, k: Int) {
    map[k] = -1 + if (map.containsKey(k)) map[k]!! else 0
}


fun isin(sum_sum : Int, n : Int) : Boolean{
    return sum_sum <= n
}
fun main(){
    val n = readLine()!!.toInt()
    var sum : Int = 0
    var sum_sum : Int = 0
    var ad = 1
    var ans = -1
    while(isin(sum_sum, n)){
        sum += ad
        sum_sum += sum
        //print("$sum $sum_sum \n")
        ad++
        ans++
    }
    print(ans)

}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var total = 0
    var level = 1
    var width = 0
    var ans = 0
    while (total <= n) {
        width += level
        total += width
        if (total <= n)
            ans = level
        // print("$width $total\n")
        level++
    }
    print("$ans\n")
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    var ans = 0
    var cost = 1
    var remaid = n
    while (remaid>=cost){
        remaid -= cost
        ans++
        cost += ans+1
    }
    println(ans)
}


fun main() {
    var n = readLine()!!.toInt()
    var cnt = 0
    var add = 0
    while(n > 0) {
        add++
        cnt += add
        n -= cnt
    }
    println(add - if (n < 0) 1 else 0)
}


import java.io.BufferedInputStream
import java.util.*

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

    val grid = Array(4, {""})
    for(i in 0..3){
        grid[i] = scanner.next()
    }

    if(ok(grid)) print("YES")
    else print("NO")
}

fun ok(g: Array<String>): Boolean{
    for(i in 0..2){
        for(j in 0..2){
            var clr1 = 0
            var clr2 = 0
            for(di in 0..1){
                for(dj in 0..1){
                    if(g[i+di][j+dj] == '.') ++clr1
                    else ++clr2
                }
            }

            if(Math.abs(clr1 - clr2) > 0){
                return true
            }
        }
    }
    return false
}


import java.lang.StringBuilder
import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val fir : String = sc.next()
    val sec : String = sc.next()
    val thi : String = sc.next()
    val fou : String = sc.next()
    val arr = arrayOf(fir, sec, thi, fou)

    for (i in 1 until 4) {
        for (j in 1 until 4) {
            var sharp = 0
            var dot = 0

            if (arr[i - 1][j - 1] == '#') sharp++
            else dot++

            if (arr[i][j - 1] == '#') sharp++
            else dot++

            if (arr[i - 1][j] == '#') sharp++
            else dot++

            if (arr[i][j] == '#') sharp++
            else dot++

            if (sharp > 2 || dot > 2) {
                print("YES")
                return
            }

        }
    }

    print("NO")

}


import java.io.BufferedReader
import java.io.InputStreamReader

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val square = List(4){br.readLine().map { if (it == '#') 1 else 0}}
    var possible = false
    for (i in 0 .. 2){
        for (j in 0 .. 2){
            val sum = square[i][j] + square[i][j + 1] +
                    square[i + 1][j] + square[i + 1][j + 1]
            if (sum != 2) {
                possible = true
                break
            }
        }
        if (possible) break
    }
    println(if (possible) "YES" else "NO")
}


  //ismail moussi
var c=Array(4)
{
    CharArray(4)
}
fun rech(i:Int,j:Int):Boolean
{
    if(i<3&&j<3)
        return c[i][j] == c[i][j + 1] && c[i][j] == c[i + 1][j] && c[i][j] == c[i + 1][j + 1]
    else
        return false
}
fun chek(): Boolean
{
    for(i in 0..3)
    {
        for(j in 0..3)
        {
            if(rech(i,j))
                return true
        }
    }
    return false
}
 fun main() {
     for (i in 0..3) {
         c[i] = readLine()!!.toCharArray()
     }
     var bool = chek()
     if (bool) {
         print("YES")
         return
     } else {
         for (i in 0..3) {
             for (j in 0..3) {
                 var old = c[i][j]
                  when (c[i][j])
                  {
                  '.'->c[i][j] = '#'
                  '#'-> c[i][j] = '.'
                  }
                   if (chek()) {
                     bool = true
                 }
                   c[i][j] = old
             }
         }
     }
     if (bool)
         print("YES")
     else print("NO")
 }


import kotlin.math.*

fun main(args: Array<String>){
	val inpt = readLine().toString().split(" ")
	val N = inpt[0]
	val A: Int = inpt[1].toInt()
	val B: Int = inpt[2].toInt()
	val rounds = round(log(N.toDouble(), 2.0)).toInt()
	val result = fround(A,B,rounds)
	if (result == rounds){
		println("Final!")
	}else{
		println(result)
	}
}

fun fround(A: Int,B: Int,rounds: Int): Int{
	var meetRound: Int = 0
	var tmpA: Int
	var tmpB: Int

	for (i in rounds downTo 1){
		tmpA = ceil(A/(2.0.pow(i-1))-0.001).toInt()
		tmpB = ceil(B/(2.0.pow(i-1))-0.001).toInt()
		if (abs(tmpA - tmpB) >= 1){
			meetRound = i
			break
		}
	}
	return(meetRound)
}


fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (numTeams, team1, team2) = readInts()
    val (minorTeam, majorTeam) = team1 minmax team2
    var numRounds = 0
    var nt = numTeams
    while (nt > 1) {
        numRounds++
        nt = nt shr 1
    }
    val queue = ArrayDeque<Triple<Int, Int, Int>>()
    queue.add(Triple(numRounds, 1, numTeams / 2))
    queue.add(Triple(numRounds, numTeams / 2 + 1, numTeams))
    while (queue.isNotEmpty()) {
        val (round, limitDown, limitUp) = queue.removeFirst()
        var where = 0
        if (minorTeam in limitDown..limitUp) where++
        if (majorTeam in limitDown..limitUp) where++
        if (where == 1) return print(if (round == numRounds) "Final!" else round)
        if (round == 1) return print(1)
        queue.addLast(Triple(round - 1, limitDown, (limitDown + limitUp) / 2))
        queue.addLast(Triple(round - 1, (limitDown + limitUp) / 2 + 1, limitUp))
    }
}

private infix fun Int.minmax(team2: Int) = if (this <= team2) this to team2 else team2 to this


import java.util.*
import kotlin.math.log2

fun main(args: Array<String>) {
    cf()
}

private fun cf() = with(Scanner(System.`in`)) {
    val n = nextInt()
    val a = nextInt()
    val b = nextInt()

    val r = round(n, a, b)
    if (isFinal(r, n))
        println("Final!")
    else
        println(r)
}

private fun isFinal(r: Int, n: Int): Boolean {
    return log2(n.toDouble()).toInt() == r
}

private fun round(n: Int, a_: Int, b_: Int): Int {
    var n = n
    var a = minOf(a_, b_)
    var b = maxOf(a_, b_)

    var games = 0

    while (true) {
        games++

        if (b % 2 == 0 && a + 1 == b) {
            return games
        }

        n /= 2
        a = (a + 1) / 2
        b = (b + 1) / 2
    }
}


import java.io.*
import java.util.*
import java.lang.System.err

private const val localFileName = "test"
private lateinit var out: PrintWriter
private lateinit var bf: BufferedReader
private var stok = StringTokenizer("")
private fun read(): String {
    while (!stok.hasMoreTokens()) stok = StringTokenizer(bf.readLine())
    return stok.nextToken()
}

private fun solve() {
    val mod = 998244353L
    val maxn = 201010
    fun Long.sqr() = this * this
    fun Long.mpow(exp: Long): Long = when {
        exp == 0L -> 1L
        (exp and 1L) == 1L -> this * this.mpow(exp - 1) % mod
        else -> this.mpow(exp / 2).sqr() % mod
    }

    val inv_2 = 2L.mpow(mod - 2)

    val fac = LongArray(maxn)
    val inv_fac = LongArray(maxn)
    fac[0] = 1
    for (i in 1 until maxn) fac[i] = (fac[i - 1] * i) % mod
    for (i in 0 until maxn) inv_fac[i] = fac[i].mpow(mod - 2)

    val pow2 = LongArray(maxn)
    pow2[0] = 1
    for (i in 1 until maxn) pow2[i] = pow2[i - 1] * 2L % mod

    fun comb(n: Int, k: Int) = fac[n] * inv_fac[k] % mod * inv_fac[n - k] % mod

    val n = read().toInt()
    val k = read().toLong()
    if (k == 1L) {
        out.println(0)
        return
    }

    val a = MutableList(n) { read().toInt() }
    var new_len = 1
    for (i in 1 until a.size) {
        if (a[i] == a[i - 1]) continue
        a[new_len++] = a[i]
    }
    if (a[0] == a[new_len - 1]) --new_len
    while (a.size != new_len) a.removeAt(a.lastIndex)

    var ans = 0L

    for (cnt0 in 0 .. a.size) {
        var cur_ans = pow2[a.size - cnt0]
        if ((a.size - cnt0) % 2 == 0)
            cur_ans = (cur_ans + mod - comb(a.size - cnt0, (a.size - cnt0) / 2)) % mod
        cur_ans = (cur_ans * inv_2) % mod
        cur_ans = cur_ans * comb(a.size, cnt0) % mod * (k - 2).mpow(cnt0.toLong()) % mod
        ans = (ans + cur_ans) % mod
    }
    ans = ans * k.mpow((n - a.size).toLong()) % mod
    out.println(ans)
}

fun main() {
    if (System.getProperty("ONLINE_JUDGE") == null) {
        assert(localFileName != "")
        System.setIn(FileInputStream(File("$localFileName.inp")))
        System.setOut(PrintStream(File("$localFileName.out")))
    }

    out = PrintWriter(System.out!!, false)
    bf = BufferedReader(InputStreamReader(System.`in`))

    solve()
    out.flush()
}


fun main(args:Array<String>) {
  val n = readLine()!!
  var ms = readLine()!!.toList().map { it.toString() }.toMutableList()

  l2@while(true) {
    l1@for( i in (0..ms.size-1-1) ) {
      //println( ms[i] + ms[i+1] )
      if( ms[i] + ms[i+1] == "01" ) {
        ms[i] = "1"
        ms[i+1] = "0"
        break@l1
      }
      if( i == ms.size-1-1 ) {
        break@l2
      }
    }
    ms = ms.joinToString("").replace("11", "1").toList().map { it.toString() }.toMutableList()
    if( ms.size == 1 ) {
      break@l2
    }
    //println(ms)
  }
  println(ms.joinToString("").replace("1{1,}".toRegex(), "1"))
}


import javax.management.Query.and

fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var s = readLine()!!
    var zero: Int = 0
    var one = false
    for (i in s) {
        zero += if (i == '0') 1 else 0
        one = (i == '1') || one
    }
    if (one) print(1)
    while (zero > 0) {
        print(0)
        zero--
    }
}