#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int N = 1024, M = N * 10;
int n, X, tot, ch[M][10], ed[M], fail[M], f[2][N * 10];
char a[N], t[N];
void insert(int len) {
  int p = 0;
  for (int i = 1; i <= len; ++i) {
    if (!ch[p][t[i]]) ch[p][t[i]] = ++tot;
    p = ch[p][t[i]];
  }
  ++ed[p];
}
int check(int len) {
  for (int i = 1; i <= len; ++i)
    for (int j = i, s = 0; j <= len; ++j)
      if ((s += t[j]) < X && X % s == 0) return 0;
  return 1;
}
void find(int sum, int len) {
  if (sum > X) return;
  if (sum == X) {
    if (check(len)) insert(len);
    return;
  }
  for (int i = 1; i < 10; ++i) t[len + 1] = i, find(sum + i, len + 1);
}
queue<int> q;
void build() {
  for (int i = 1; i < 10; ++i)
    if (ch[0][i]) q.push(ch[0][i]), fail[ch[0][i]] = 0;
  while (!q.empty()) {
    int 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];
  }
}
signed main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  for (int i = 1; i <= n; ++i) a[i] -= '0';
  read(X);
  find(0, 0);
  build();
  memset(f, 0x3f, sizeof(f));
  f[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    int k = (i & 1);
    memset(f[k], 0x3f, sizeof(f[k]));
    for (int j = 0; j <= tot; ++j) {
      f[k][j] = min(f[k][j], f[k ^ 1][j] + 1);
      int tmp = ch[j][a[i]];
      if (!ed[tmp]) f[k][tmp] = min(f[k][tmp], f[k ^ 1][j]);
    }
  }
  int res = 1e9;
  for (int i = 0; i <= tot; ++i) res = min(res, f[n & 1][i]);
  return printf("%d\n", res), 0;
}
