#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
void read(Tp &x) {
  int fh = 1;
  char c = getchar();
  x = 0;
  while (c > '9' || c < '0') {
    if (c == '-') {
      fh = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c & 15);
    c = getchar();
  }
  x *= fh;
}
int n, m, X;
string s0;
int ch[2505 * 10][10], fail[2505 * 10], edp[2505 * 20], tot;
void ins(string ss) {
  int p = 0;
  for (unsigned i = 0; i < ss.size(); i++) {
    int dir = ss[i] - '0';
    if (!ch[p][dir]) ch[p][dir] = ++tot;
    p = ch[p][dir];
  }
  edp[p]++;
}
void build() {
  queue<int> q;
  int p = 0;
  for (int i = 1; i < 10; i++)
    if (ch[0][i]) q.push(ch[0][i]), fail[ch[0][i]] = 0;
  while (!q.empty()) {
    p = q.front();
    q.pop();
    for (int i = 1; i < 10; i++) {
      if (ch[p][i])
        fail[ch[p][i]] = ch[fail[p]][i], q.push(ch[p][i]);
      else
        ch[p][i] = ch[fail[p]][i];
    }
  }
}
int dp[2][2505 * 10];
int check(string ss) {
  int sm = 0;
  for (int l = 0; l < ss.size(); l++) {
    sm = 0;
    for (int r = l; r < ss.size(); r++) {
      sm += ss[r] - '0';
      if (sm != X && X % sm == 0) return 0;
    }
  }
  return 1;
}
void generate(string st, int sm) {
  if (sm > X) return;
  if (sm == X) {
    if (check(st)) ins(st);
    return;
  }
  for (int i = 1; i < 10; i++) {
    generate(st + (char)(i + '0'), sm + i);
  }
}
signed main() {
  cin >> s0;
  n = s0.size();
  read(X);
  generate("", 0);
  build();
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0;
  int p = 1, q = 0;
  for (int i = 0; i < n; i++) {
    swap(p, q);
    for (int j = 0; j <= tot; j++) dp[q][j] = 0x3f3f3f3f;
    for (int j = 0; j <= tot; j++) {
      dp[q][j] = min(dp[q][j], dp[p][j] + 1);
      if (!edp[ch[j][s0[i] - '0']])
        dp[q][ch[j][s0[i] - '0']] = min(dp[q][ch[j][s0[i] - '0']], dp[p][j]);
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i <= tot; i++) ans = min(ans, dp[q][i]);
  printf("%d\n", ans);
  return 0;
}
