#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = 25, K = 5005;
char s[N];
int n, x, p[M], f[N][K], t[K][10], fail[K];
int head, tail, q[K], cnt, ans;
bool c[K];
bool check(int len) {
  int tmp = 0;
  for (int i = len; i >= 1; --i) {
    tmp += p[i];
    if (tmp != x && x % tmp == 0) return 0;
  }
  return 1;
}
void build(int len) {
  int x = 1;
  for (int i = 1; i <= len; ++i)
    if (t[x][p[i]])
      x = t[x][p[i]];
    else
      t[x][p[i]] = ++cnt, x = cnt;
  c[x] = 1;
}
void acam() {
  for (int i = 1; i <= 9; ++i) t[0][i] = 1;
  q[head = tail = 0] = 1;
  while (head <= tail) {
    int x = q[head++];
    for (int i = 1; i <= 9; ++i)
      if (t[x][i]) {
        int k = fail[x];
        fail[t[x][i]] = t[k][i];
        q[++tail] = t[x][i];
      } else
        t[x][i] = t[fail[x]][i];
    c[x] |= c[fail[x]];
  }
}
void dfs(int len, int tot) {
  if (tot == x) {
    build(len);
    return;
  }
  for (int i = 1; i <= min(9, x - tot); ++i) {
    p[len + 1] = i;
    if (check(len + 1)) dfs(len + 1, tot + i);
  }
}
void init() {
  cnt = 1, dfs(0, 0);
  acam();
}
void chkmax(int &x, int y) { x = max(x, y); }
void dp() {
  for (int i = 0; i <= n; ++i)
    for (int j = 1; j <= cnt; ++j) f[i][j] = -n;
  f[0][1] = 0;
  for (int i = 0; i <= n - 1; ++i)
    for (int j = 1; j <= cnt; ++j)
      if (!c[j] && f[i][j] >= 0) {
        chkmax(f[i + 1][j], f[i][j]);
        chkmax(f[i + 1][t[j][s[i + 1] - '0']], f[i][j] + 1);
      }
  for (int i = 1; i <= cnt; ++i)
    if (!c[i]) chkmax(ans, f[n][i]);
  printf("%d\n", n - ans);
}
int main() {
  scanf("%s", s + 1), n = strlen(s + 1);
  scanf("%d", &x);
  init();
  dp();
  return 0;
}
