#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int M = 2e4 + 10;
const int INF = 0x3f3f3f3f;
char s[N];
struct AC_Automata {
  int root, tree[M][10], tot;
  int fail[M], idx[M], st[M];
  int qu[M], head, tail;
  int newnode() {
    for (int i = 0; i < 10; i++) tree[tot][i] = 0;
    fail[tot] = idx[tot] = st[tot] = 0;
    return tot++;
  }
  void init() {
    tot = 0;
    root = newnode();
  }
  void insert(string s) {
    int cur = root;
    for (int i = 1; s[i]; i++) {
      int tmp = s[i] - '0';
      if (!tree[cur][tmp]) tree[cur][tmp] = newnode();
      cur = tree[cur][tmp];
    }
    st[cur] = 1;
  }
  void build() {
    head = 1, tail = 0;
    for (int i = 0; i < 10; i++)
      if (tree[0][i]) qu[++tail] = tree[0][i];
    while (head <= tail) {
      int cur = qu[head++];
      for (int i = 0; i < 10; i++) {
        int tmp = tree[cur][i];
        if (tmp)
          fail[tmp] = tree[fail[cur]][i], qu[++tail] = tmp;
        else
          tree[cur][i] = tree[fail[cur]][i];
      }
    }
    for (int i = 1; i <= tail; i++) st[qu[i]] |= st[fail[qu[i]]];
  }
} ac;
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  int x;
  scanf("%d", &x);
  ac.init();
  string t = " ";
  vector<int> pre(21, 0);
  function<void(int)> dfs = [&](int pos) {
    if (pre[pos - 1] == x) {
      for (int j = 1; j < pos; j++)
        for (int k = j; k < pos; k++) {
          int val = pre[k] - pre[j - 1];
          if (val != x && x % val == 0) return;
        }
      ac.insert(t);
      return;
    }
    for (int j = 1; j <= 10; j++) {
      if (pre[pos - 1] + j > x) break;
      t.push_back('0' + j);
      pre[pos] = pre[pos - 1] + j;
      dfs(pos + 1);
      t.pop_back();
    }
  };
  dfs(1);
  ac.build();
  vector<vector<int>> dp(n + 1, vector<int>(ac.tot, INF));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int op = s[i] - '0';
    for (int j = 0; j < ac.tot; j++) {
      int to = ac.tree[j][op];
      if (!ac.st[to]) dp[i][to] = min(dp[i][to], dp[i - 1][j]);
      if (!ac.st[j]) dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
    }
  }
  printf("%d\n", *min_element(dp[n].begin(), dp[n].end()));
  return 0;
}
