#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
char c[1005];
int k;
int dp[2][1 << 20];
int ma[1 << 21], cnt, to[1 << 20][11], lst[30], td[2][1 << 20], tc[2];
bool ch[1 << 21], in[1 << 20];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  scanf("%s%d", c + 1, &k);
  int n = strlen(c + 1);
  bool tf = 1;
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    bool ff = 1, cf = 1;
    for (int j = i; j <= n; j++) {
      sum += c[j] - '0';
      if (sum > k) break;
      if (sum == k) {
        if (ff) cf = 0;
        break;
      }
      int ts = 0;
      for (int tt = j; tt >= i; tt--) {
        ts += c[tt] - '0';
        if (k % ts == 0) {
          ff = 0;
        }
      }
    }
    if (!cf) {
      tf = 0;
      break;
    }
  }
  if (tf) {
    cout << 0;
    return 0;
  }
  for (int mk = 0; mk < 1 << (k + 1); mk++) {
    if (!(mk & (1 << k))) {
      ma[++cnt] = mk;
      ch[mk] = 1;
      continue;
    }
    bool ff = 1;
    int nc = 0;
    for (int j = 0; j < k + 1; j++)
      if (mk & (1 << j)) {
        for (int ti = 1; ti <= nc; ti++)
          if ((j - lst[ti] != k && k % (j - lst[ti]) == 0)) {
            ff = 0;
            break;
          }
        if (!ff) break;
        lst[++nc] = j;
      }
    if (!ff) {
      ma[++cnt] = mk;
      ch[mk] = 1;
      continue;
    }
  }
  for (int mk = 1; mk < 1 << k; mk++) {
    for (int j = 1; j < 10; j++) {
      int now = (mk << j) + 1;
      now &= (1 << (k + 1)) - 1;
      if (ch[now]) to[mk][j] = now & ((1 << k) - 1);
    }
  }
  int now = 1, maxi = 0;
  for (int i = 0; i <= 1; i++)
    for (int mk = 0; mk < 1 << k; mk++) dp[i][mk] = -2147483647;
  dp[0][1] = 0;
  td[0][++tc[0]] = 1;
  for (int i = 1; i <= n; i++) {
    now ^= 1;
    for (int j = 1; j <= tc[now]; j++) in[td[now][j]] = 0;
    tc[now ^ 1] = 0;
    for (int j = 1; j <= tc[now]; j++) {
      int mk = td[now][j];
      if (to[mk][c[i] - '0']) {
        int &tn = dp[now ^ 1][to[mk][c[i] - '0']];
        if (dp[now][mk] + 1 >= tn) {
          tn = dp[now][mk] + 1;
          maxi = max(maxi, tn);
          if (tn > maxi - k && !in[to[mk][c[i] - '0']])
            td[now ^ 1][++tc[now ^ 1]] = to[mk][c[i] - '0'],
                                   in[to[mk][c[i] - '0']] = 1;
        }
      }
      int &tn = dp[now ^ 1][mk];
      if (dp[now][mk] >= tn) {
        tn = dp[now][mk];
        maxi = max(maxi, tn);
        if (tn > maxi - k && !in[mk])
          td[now ^ 1][++tc[now ^ 1]] = mk, in[mk] = 1;
      }
    }
  }
  cout << n - maxi;
  return 0;
}
