import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
long s = sc.nextInt();
long n = str.length();
int tot = 0;
long[] a = new long[100031];
long[][] num = new long[55][55], dp = new long[55][100031];
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) != '0') {
a[++tot] = str.charAt(i) - '0';
}
}
for (int i = 1; i <= tot; i++) {
num[i][i] = a[i];
for (int j = i; j - i <= 11 && j <= tot; j++) {
num[i][j] = num[i][j - 1] * 10 + a[j];
}
}
for (int i = 0; i <= tot + 1; i++) {
for (int j = 0; j <= s + 1; j++) {
dp[i][j] = Integer.MAX_VALUE;
}
}
dp[0][0] = 0;
for (int i = 1; i <= tot; i++) {
for (int k = 1; k <= 11; k++) {
if (i >= k) {
for (int j = (int) num[i - k + 1][i]; j <= s; j++) {
dp[i][j] = Math.min(dp[i][j], dp[i - k][j - (int) num[i - k + 1][i]] + 1);
}
}
}
}
if (dp[tot][(int) s] > tot) System.out.println(-1);
else System.out.println(dp[tot][(int) s] - 1);
sc.close();
}
}