#include <bits/stdc++.h>
const int M = 5000;
int fail[M], ch[M][10], pre[30], a[30], n, cnt, end[M], K, dp[2][M];
char s[1005];
std::queue<int> q;
void insert(int n) {
  int u = 0;
  for (int i = 1; i <= n; i++) {
    if (!ch[u][a[i]]) ch[u][a[i]] = ++cnt;
    u = ch[u][a[i]];
  }
  end[u] = 1;
}
void dfs(int step, int sum) {
  if (sum == K) {
    insert(step - 1);
    return;
  }
  for (int i = 1; i <= 9 && i + sum <= K; i++) {
    pre[step] = pre[step - 1] + i;
    int tg = 1;
    for (int j = (pre[step] == K); j < step; j++)
      if (K % (pre[step] - pre[j]) == 0) {
        tg = 0;
        break;
      }
    if (tg == 0) continue;
    a[step] = i;
    dfs(step + 1, pre[step]);
  }
}
void get_fail() {
  for (int i = 1; i <= 9; i++)
    if (ch[0][i]) q.push(ch[0][i]);
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = 1; i <= 9; i++)
      if (ch[x][i]) {
        q.push(ch[x][i]);
        fail[ch[x][i]] = ch[fail[x]][i];
      } else
        ch[x][i] = ch[fail[x]][i];
  }
}
void Min(int &x, int y) {
  if (y < x) x = y;
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%d", &K);
  dfs(1, 0);
  get_fail();
  memset(dp, 0x3f, sizeof(dp));
  int now = 0;
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    now = now ^ 1;
    memset(dp[now], 0x3f, sizeof(dp[now]));
    for (int j = 0; j <= cnt; j++) {
      int t = dp[now ^ 1][j];
      Min(dp[now][j], t + 1);
      int u = ch[j][s[i] - '0'];
      if (!end[u]) Min(dp[now][u], t);
    }
  }
  int ans = n;
  for (int i = 0; i <= cnt; i++) Min(ans, dp[now][i]);
  printf("%d\n", ans);
}
