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

fun abc106c() {
    val s = readLine()!!
    val k = readLine()!!.toLong()

    val notOneString = s.findAnyOf((2..9).map { it.toString() })

    val answer = if (notOneString == null || notOneString.first >= k) {
        "1"
    } else {
        notOneString.second
    }

    println(answer)
}
