#include <bits/stdc++.h>
using namespace std;
const int N = 1123;
const int M = 50 * N;
char str[N];
int dp[N][M];
struct aho_corasick {
  struct node {
    int link;
    bool end;
    map<char, int> to;
    bool has(char c) { return to.find(c) != to.end(); }
  };
  vector<node> nodes;
  aho_corasick() { nodes.emplace_back(); }
  void insert(string& s) {
    int current = 0;
    for (auto c : s) {
      if (!nodes[current].has(c)) {
        nodes[current].to[c] = nodes.size();
        nodes.emplace_back();
      }
      current = nodes[current].to[c];
    }
    nodes[current].end = true;
  }
  void build_links() {
    queue<int> q;
    nodes[0].link = -1;
    q.push(0);
    while (q.size()) {
      int u = q.front();
      q.pop();
      for (auto e : nodes[u].to) {
        int& link = nodes[e.second].link;
        link = nodes[u].link;
        while (link != -1 && !nodes[link].has(e.first)) link = nodes[link].link;
        link = (link == -1) ? 0 : nodes[link].to[e.first];
        q.push(e.second);
      }
    }
  }
  int search(int p, string& s, int current = 0) {
    if (dp[p][current] != N) return dp[p][current];
    if (nodes[current].end) return dp[p][current] = N + 1;
    if (p == s.size()) return dp[p][current] = 0;
    int& resp = dp[p][current];
    resp = search(p + 1, s, current) + 1;
    char c = s[p];
    int next = current;
    while (next != -1 && !nodes[next].has(c)) next = nodes[next].link;
    if (next == -1)
      next = 0;
    else
      next = nodes[next].to[c];
    resp = min(resp, search(p + 1, s, next));
    return resp;
  }
};
aho_corasick ac;
void make(int x, string s = "", int sum = 0) {
  if (sum > x) return;
  int d = 0;
  for (int j = int(s.size()) - 1; j >= 0; j--) {
    d += (s[j] - '0');
    if (d < x && x % d == 0) return;
  }
  if (sum == x) {
    ac.insert(s);
  }
  for (int i = '1'; i <= '9'; i++) {
    s.push_back(i);
    make(x, s, sum + (i - '0'));
    s.pop_back();
  }
}
int main() {
  int x;
  scanf("%s %d", str, &x);
  string s(str);
  int n = s.size();
  make(x);
  ac.build_links();
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) dp[i][j] = N;
  ac.search(0, s);
  printf("%d\n", min_element(dp[0], dp[0] + M)[0]);
}
