#include <bits/stdc++.h>
using namespace std;
const int maxn = 6009;
const int inf = 1e9;
int n, x;
char s[maxn];
char t[maxn];
int nn = 1;
int ch[maxn][10], fa[maxn], h[maxn];
void insert() {
  int x = 1;
  for (int i = 1; t[i] != '\0'; ++i) {
    int c = t[i] - '0';
    if (!ch[x][c]) {
      ch[x][c] = ++nn;
      fa[ch[x][c]] = x;
    }
    x = ch[x][c];
  }
  h[x] = 1;
}
int check() {
  int len = strlen(t + 1);
  for (int i = 1; i <= len; ++i) {
    int sum = 0;
    for (int j = i; j <= len; ++j) {
      sum = (sum + t[j] - '0');
      if (sum != x && x % sum == 0) return 0;
    }
  }
  return 1;
}
void dfs(int now, int sum) {
  if (sum == x) {
    t[now] = '\0';
    if (check()) insert();
  }
  for (int i = 1; i <= min(x - sum, 9); ++i) {
    t[now] = '0' + i;
    dfs(now + 1, sum + i);
  }
}
queue<int> q;
int fail[maxn];
void buildfail() {
  fail[1] = 1;
  for (int i = 1; i <= 9; ++i) {
    int v = ch[1][i];
    if (!v) {
      ch[1][i] = 1;
    } else {
      fail[v] = 1;
      q.push(v);
    }
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 1; i <= 9; ++i) {
      int v = ch[x][i];
      if (!v) {
        ch[x][i] = ch[fail[x]][i];
      } else {
        fail[ch[x][i]] = ch[fail[x]][i];
        q.push(v);
      }
    }
  }
  for (int i = 2; i <= nn; ++i) {
    h[x] = h[x] | h[fa[x]] | h[fail[x]];
  }
}
int f[1009][maxn];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%d", &x);
  dfs(1, 0);
  buildfail();
  for (int i = 0; i <= n; ++i) {
    for (int j = 1; j <= nn; ++j) {
      f[i][j] = inf;
    }
  }
  f[0][1] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= nn; ++j) {
      if (f[i][j] == inf) continue;
      f[i + 1][j] = min(f[i + 1][j], f[i][j] + 1);
      int y = ch[j][s[i + 1] - '0'];
      if (h[y]) continue;
      f[i + 1][y] = min(f[i + 1][y], f[i][j]);
    }
  }
  int ans = inf;
  for (int i = 1; i <= nn; ++i) ans = min(ans, f[n][i]);
  printf("%d\n", ans);
  return 0;
}
