#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5050;
int link[MAXN][10];
int fail[MAXN];
int f[1010][MAXN];
bool mark[MAXN];
int node = 0, root = 1;
char s[MAXN];
int x;
int a[25], b[25];
int len;
void ins(int &rt, int l) {
  if (!rt) rt = ++node;
  if (l > len) {
    mark[rt] = 1;
    return;
  }
  ins(link[rt][a[l]], l + 1);
}
queue<int> q;
void getfail() {
  fail[root] = root;
  for (int i = 1; i <= 9; ++i)
    if (link[root][i]) {
      fail[link[root][i]] = root;
      q.push(link[root][i]);
    } else
      link[root][i] = root;
  while (q.size() > 0) {
    int c = q.front();
    q.pop();
    for (int i = 1; i <= 9; ++i)
      if (link[c][i]) {
        fail[link[c][i]] = link[fail[c]][i];
        mark[link[c][i]] |= mark[link[fail[c]][i]];
        q.push(link[c][i]);
      } else
        link[c][i] = link[fail[c]][i];
  }
}
void bruteforce(int sum) {
  if (!sum) {
    ins(root, 1);
    return;
  }
  ++len;
  for (int i = 1; i <= min(sum, 9); ++i) {
    a[len] = i;
    b[len] = b[len - 1] + i;
    bool flag = 1;
    for (int j = 0; j < len; ++j)
      if (b[len] - b[j] != x && x % (b[len] - b[j]) == 0) flag = 0;
    if (flag) bruteforce(sum - i);
  }
  len--;
}
int main() {
  cin >> s + 1 >> x;
  len = 0;
  node = 1;
  bruteforce(x);
  getfail();
  f[0][1] = 0;
  for (int i = 2; i <= node; ++i) f[0][i] = -2000;
  int m = strlen(s + 1);
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= node; ++j) f[i][j] = f[i - 1][j];
    for (int j = 1; j <= node; ++j)
      if (f[i - 1][j] != -2000 && !mark[link[j][s[i] - '0']])
        f[i][link[j][s[i] - '0']] =
            max(f[i][link[j][s[i] - '0']], f[i - 1][j] + 1);
  }
  int ans = 0;
  for (int i = 1; i <= node; ++i) ans = max(ans, f[m][i]);
  printf("%d\n", m - ans);
  return 0;
}
