Additions

더하기와 숫자로 된 문자열에서 최소 개수의 문자를 바꿔, 선행 0과 단항 플러스를 허용하지 않는 유효한 수식이면서 계산 결과가 N 이하가 되도록 만든다.

어려움8동적 계획법그리디구현문자열아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

You are given an integer NN and a string consisting of + and digits. You are asked to transform the string into a valid formula whose calculation result is smaller than or equal to NN by modifying some characters. Here, you replace one character with another character any number of times, and the converted string should still consist of + and digits. Note that leading zeros and unary positive are prohibited.

For instance, 0123+456 is assumed as invalid because leading zero is prohibited. Similarly, +1+2 and 2++3 are also invalid as they each contain a unary expression. On the other hand, 12345, 0+1+2 and 1234+0+0 are all valid.

Your task is to find the minimum number of the replaced characters. If there is no way to make a valid formula smaller than or equal to NN, output 1-1 instead of the number of the replaced characters.

입력

The input consists of a single test case in the following format.

$N$
$S$

The first line contains an integer NN, which is the upper limit of the formula (1N1091 \le N \le 10^9). The second line contains a string SS, which consists of + and digits and whose length is between 11 and 1,0001{,}000, inclusive. Note that it is not guaranteed that initially SS is a valid formula.

출력

Output the minimized number of the replaced characters. If there is no way to replace, output 1-1 instead.

힌트

In the first example, you can modify the first two characters and make a formula 1+23, for instance. In the second example, you should make 0+10 or 10+0 by replacing all the characters. In the third example, you cannot make any valid formula less than or equal to 11.