#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}
template <char MIN_CHAR = 'a', int ALPHABET = 26>
struct aho_corasick {
  struct node {
    int suff = -1, dict = -1, depth = 0;
    int word_index = -1, word_count = 0;
    int link[ALPHABET];
    node() { fill(link, link + ALPHABET, -1); }
    int &operator[](char c) { return link[c - MIN_CHAR]; }
  };
  vector<node> nodes;
  int W;
  vector<int> word_location;
  vector<int> word_indices_by_depth;
  vector<int> defer;
  aho_corasick(const vector<string> &words = {}) {
    if (!words.empty()) build(words);
  }
  vector<vector<int>> build_suffix_adj() const {
    vector<vector<int>> adj(nodes.size());
    for (int i = 1; i < int(nodes.size()); i++) adj[nodes[i].suff].push_back(i);
    return adj;
  }
  int get_or_add_child(int current, char c) {
    if (nodes[current][c] >= 0) return nodes[current][c];
    int index = int(nodes.size());
    nodes[current][c] = index;
    nodes.emplace_back();
    nodes.back().depth = nodes[current].depth + 1;
    return index;
  }
  int add_word(const string &word, int word_index) {
    assert(!nodes.empty());
    int current = 0;
    for (char c : word) current = get_or_add_child(current, c);
    if (nodes[current].word_index < 0) nodes[current].word_index = word_index;
    nodes[current].word_count++;
    return current;
  }
  int get_suffix_link(int location, char c) const {
    if (location >= 0) location = nodes[location].link[c - MIN_CHAR];
    return max(location, 0);
  }
  void build(const vector<string> &words) {
    nodes = {node()};
    W = int(words.size());
    word_location.resize(W);
    defer.resize(W);
    int max_depth = 0;
    for (int i = 0; i < W; i++) {
      word_location[i] = add_word(words[i], i);
      max_depth = max(max_depth, int(words[i].size()));
      defer[i] = nodes[word_location[i]].word_index;
    }
    word_indices_by_depth.resize(W);
    vector<int> depth_freq(max_depth + 1, 0);
    for (int i = 0; i < W; i++) depth_freq[words[i].size()]++;
    for (int i = max_depth - 1; i >= 0; i--) depth_freq[i] += depth_freq[i + 1];
    for (int i = 0; i < W; i++)
      word_indices_by_depth[--depth_freq[words[i].size()]] = i;
    vector<int> q = {0};
    for (int i = 0; i < int(q.size()); i++) {
      int current = q[i];
      for (char c = MIN_CHAR; c < MIN_CHAR + ALPHABET; c++) {
        int &index = nodes[current][c];
        if (index >= 0) {
          int suffix_parent = get_suffix_link(nodes[current].suff, c);
          nodes[index].suff = suffix_parent;
          nodes[index].word_count += nodes[suffix_parent].word_count;
          nodes[index].dict = nodes[suffix_parent].word_index < 0
                                  ? nodes[suffix_parent].dict
                                  : suffix_parent;
          q.push_back(index);
        } else {
          index = get_suffix_link(nodes[current].suff, c);
        }
      }
    }
  }
  vector<int> count_matches(const string &text) const {
    vector<int> matches(W, 0);
    int current = 0;
    for (char c : text) {
      current = get_suffix_link(current, c);
      int dict_node =
          nodes[current].word_index < 0 ? nodes[current].dict : current;
      if (dict_node >= 0) matches[nodes[dict_node].word_index]++;
    }
    for (int word_index : word_indices_by_depth) {
      int location = word_location[word_index];
      int dict_node = nodes[location].dict;
      if (dict_node >= 0)
        matches[nodes[dict_node].word_index] += matches[word_index];
    }
    for (int i = 0; i < W; i++) matches[i] = matches[defer[i]];
    return matches;
  }
  vector<int> count_matches_by_position(const string &text) const {
    vector<int> matches(text.size());
    int current = 0;
    for (int i = 0; i < int(text.size()); i++) {
      current = get_suffix_link(current, text[i]);
      matches[i] = nodes[current].word_count;
    }
    return matches;
  }
  int64_t count_total_matches(const string &text) const {
    int64_t matches = 0;
    int current = 0;
    for (char c : text) {
      current = get_suffix_link(current, c);
      matches += nodes[current].word_count;
    }
    return matches;
  }
};
const int INF = 1e9 + 5;
int N, X;
string S;
vector<string> prime;
aho_corasick<'1', 9> AC;
bool check(string str) {
  int n = int(str.size());
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j < n; j++) {
      sum += str[j] - '0';
      if (sum < X && X % sum == 0) return false;
    }
  }
  return true;
}
void generate(string str, int sum) {
  if (sum > X) return;
  if (sum == X) {
    if (check(str)) prime.push_back(str);
    return;
  }
  for (int d = 1; d <= 9 && sum + d <= X; d++)
    generate(str + char(d + '0'), sum + d);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> S >> X;
  N = int(S.size());
  generate("", 0);
  ;
  AC.build(prime);
  int ST = int(AC.nodes.size());
  vector<int> dp(ST, INF);
  dp[0] = 0;
  for (auto &ch : S) {
    vector<int> next_dp(ST, INF);
    for (int state = 0; state < ST; state++)
      if (dp[state] < INF) {
        next_dp[state] = min(next_dp[state], dp[state] + 1);
        int transition = AC.get_suffix_link(state, ch);
        if (AC.nodes[transition].word_index < 0)
          next_dp[transition] = min(next_dp[transition], dp[state]);
      }
    swap(dp, next_dp);
  }
  cout << *min_element(dp.begin(), dp.end()) << '\n';
}
