#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
  register T f = 1;
  register char ch = getchar();
  t = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  t *= f;
  return t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const long long p = 998244353;
inline long long power(register long long x, register long long k = p - 2) {
  register long long re = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) re = re * x % p;
  return re;
}
char c[1005];
int n, x;
char s[55];
int top;
bool ck() {
  int S = 0;
  for (int i = 1; i <= top; i++) S += s[i] - '0';
  for (int l = 1; l <= top; l++)
    for (int r = l; r <= top; r++) {
      int sum = 0;
      for (int i = l; i <= r; i++) sum += s[i] - '0';
      if (S % sum == 0 && S != sum) return 0;
    }
  return 1;
}
int ans;
struct ACM {
  int trie[50005][9];
  int fail[50005];
  int tot;
  bool endpos[50005];
  inline void Insert(char* s) {
    int p = 0;
    for (int i = 0; s[i]; i++) {
      if (trie[p][s[i] - '1'] == 0) trie[p][s[i] - '1'] = ++tot;
      p = trie[p][s[i] - '1'];
    }
    endpos[p] = 1;
  }
  void build_fail() {
    queue<int> q;
    for (int i = 0; i < 9; i++)
      if (trie[0][i]) q.push(trie[0][i]);
    while (q.size()) {
      int p = q.front();
      q.pop();
      for (int i = 0; i < 9; i++)
        if (trie[p][i])
          fail[trie[p][i]] = trie[fail[p]][i], q.push(trie[p][i]);
        else
          trie[p][i] = trie[fail[p]][i];
    }
  }
} T;
void dfs(int S) {
  if (S == 0) {
    if (ck()) {
      s[top + 1] = '\0';
      T.Insert(s + 1);
    }
    return;
  }
  for (int i = 1; i <= 9 && i <= S; i++) s[++top] = i + '0', dfs(S - i), top--;
}
int f[1005][50005];
int main() {
  scanf("%s", c + 1);
  n = strlen(c + 1);
  read(x);
  dfs(x);
  T.build_fail();
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= T.tot; j++) {
      if (f[i][j] > i) continue;
      int id = T.trie[j][c[i + 1] - '1'];
      if (T.endpos[id] == 0) f[i + 1][id] = min(f[i + 1][id], f[i][j]);
      f[i + 1][j] = min(f[i + 1][j], f[i][j] + 1);
    }
  int ans = 1e9;
  for (int i = 0; i <= T.tot; i++) ans = min(ans, f[n][i]);
  printf("%d", ans);
  return 0;
}
