fun Boolean.toInt(): Int = if (this) 1 else 0
fun main(args: Array<String>?): Unit {
    val n = readLine()!!.trim().toLong()
    val s = readLine()!!.trim()
    val memo = Array(s.length){i -> Array(2){Array(11){LongArray(s.length - i){-1L}}}}
    val digit: LongArray = LongArray(10){(0 until it).fold(1L){a, _ -> a * 10}}
    fun sub(i: Int, zeroAllow: Boolean, d: Int, c: Int): Long {
        if (c < 0) return n + 1L
        if (i == s.length) return if (d == 10) 0L else n + 1L
        if (c >= s.length - i) {
            return when(d) {
                10 -> if (s.length - i == 1) n + 1L else if ((s.length - i) % 2 == 0) 0L else 10L
                0 -> sub(i + 1, zeroAllow, 10, c - 1)
                else -> if (zeroAllow) sub(i + 1, true, d - 1, c - 1) else sub(i + 1, true, d - 1, c - 1) + digit[d]
            }
        }
        if (memo[i][zeroAllow.toInt()][d][c] >= 0) return memo[i][zeroAllow.toInt()][d][c]
        memo[i][zeroAllow.toInt()][d][c] = when(d) {
            10 -> when(s[i]){
                '+' -> (0..9).map{j -> sub(i + 1, false, j, c)}.min()!!
                else -> (0..9).map{j -> sub(i + 1, false, j, c - 1)}.min()!!
            }
            0 -> when(s[i]) {
                '+' -> sub(i + 1, false,10, c - 1)
                '0' -> sub(i + 1, false, 10, c)
                else -> Math.min(sub(i + 1, false, 10, c - 1), sub(i + 1, false, 10, c) + (s[i] - '0'))
            }
            else -> when(s[i]) {
                '+' -> if (zeroAllow) sub(i + 1, true, d - 1, c - 1) else (sub(i + 1, true, d - 1, c - 1) + digit[d])
                '0' -> if (zeroAllow) sub(i + 1, true, d - 1, c) else (sub(i + 1, true, d - 1, c - 1) + digit[d])
                else -> if (zeroAllow) Math.min(sub(i + 1, true, d - 1, c - 1), sub(i + 1, true, d - 1, c) + (s[i] - '0') * digit[d]) else Math.min(sub(i + 1, true, d - 1, c - 1) + digit[d], sub(i + 1, true, d - 1, c) + (s[i] - '0') * digit[d])
            }
        }
        if (memo[i][zeroAllow.toInt()][d][c] > n) {
            memo[i][zeroAllow.toInt()][d][c] = n + 1L
        }
        return memo[i][zeroAllow.toInt()][d][c]
    }
    println((0 .. s.length).filter{c -> (0 .. 9).map{d -> sub(0, false, d, c)}.any{it <= n}}.min() ?: -1)
}


