#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, flag = 1;
  char c = getchar();
  while ((c > '9' || c < '0') && c != '-') c = getchar();
  if (c == '-') flag = 0, c = getchar();
  while (c <= '9' && c >= '0') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return flag ? x : -x;
}
struct Trie {
  int tot;
  int (*t)[9], *e, *fail;
  Trie(int n) {
    tot = 0;
    t = new int[n][9]();
    e = new int[n]();
    fail = new int[n]();
  }
  void insert(char *s) {
    int p = 0;
    for (int i = 0; s[i]; i++) {
      int k = s[i] - '1';
      if (!t[p][k]) t[p][k] = ++tot;
      p = t[p][k];
    }
    e[p]++;
  }
  void get_fail() {
    queue<int> Q;
    for (int i = (0); i <= (int)(9 - 1); i++)
      if (t[0][i]) Q.push(t[0][i]);
    while (!Q.empty()) {
      int k = Q.front();
      Q.pop();
      if (e[fail[k]]) e[k] = e[fail[k]];
      for (int i = (0); i <= (int)(9 - 1); i++)
        if (t[k][i])
          fail[t[k][i]] = t[fail[k]][i], Q.push(t[k][i]);
        else
          t[k][i] = t[fail[k]][i];
    }
  }
};
const int maxn = 5005, inf = 1e8;
int a[25], s[25];
char t[1005], p[1005];
Trie trie(maxn);
int f[1005][maxn];
void get(int k, int sum, int x) {
  if (sum > x) return;
  if (sum == x) {
    s[1] = a[1];
    for (int i = (2); i <= (int)(k - 1); i++) s[i] = s[i - 1] + a[i];
    int flag = 1;
    for (int i = 1; i <= k - 1; i++)
      for (int j = i; j <= k - 1; j++)
        if (s[j] - s[i - 1] != x && x % (s[j] - s[i - 1]) == 0) {
          flag = 0;
          break;
        }
    if (flag) {
      for (int i = (1); i <= (int)(k - 1); i++) t[i] = a[i] + '0';
      t[k] = 0;
      trie.insert(t + 1);
    }
    return;
  }
  for (int i = 1; i <= 9; i++)
    if (sum + i <= x) a[k] = i, get(k + 1, sum + i, x);
}
int main() {
  scanf("%s", p + 1);
  int x = read();
  get(1, 0, x);
  trie.get_fail();
  int n = strlen(p + 1), tot = trie.tot;
  for (int i = (0); i <= (int)(n); i++)
    for (int j = (0); j <= (int)(tot); j++) f[i][j] = inf;
  f[0][0] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j <= tot; j++) {
      f[i][j] = min(f[i][j], f[i - 1][j] + 1);
      int v = trie.t[j][p[i] - '1'];
      if (!trie.e[v]) f[i][v] = min(f[i][v], f[i - 1][j]);
    }
  int ans = inf;
  for (int j = 0; j <= tot; j++) ans = min(ans, f[n][j]);
  cout << ans;
  return 0;
}
