#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <long long K, class T>
struct PatternMatching {
  struct Node {
    long long c;
    std::array<long long, K> nxt;
    long long fail;
    bool matched;
    explicit Node(long long c) : c(c), fail(0), matched(false) { nxt.fill(-1); }
  };
  std::vector<Node> nodes;
  std::function<long long(T)> enc;
  explicit PatternMatching(T base) {
    nodes.emplace_back(-1);
    enc = [=](T c) { return c - base; };
  }
  explicit PatternMatching(const std::function<long long(T)>& enc) : enc(enc) {
    nodes.emplace_back(-1);
  }
  template <class Container>
  void add(const Container& s) {
    long long pos = 0;
    for (T ci : s) {
      long long c = enc(ci);
      long long npos = nodes[pos].nxt[c];
      if (npos == -1) {
        npos = nodes.size();
        nodes[pos].nxt[c] = npos;
        nodes.emplace_back(c);
      }
      pos = npos;
    }
    nodes[pos].matched = true;
  }
  long long next(long long pos, long long c) const {
    while (nodes[pos].nxt[c] == -1) pos = nodes[pos].fail;
    return nodes[pos].nxt[c];
  }
  void build() {
    std::queue<long long> que;
    for (long long& pos : nodes[0].nxt) {
      if (pos == -1) {
        pos = 0;
      } else {
        que.push(pos);
      }
    }
    while (!que.empty()) {
      long long pos = que.front();
      que.pop();
      for (long long c = 0; c < K; ++c) {
        long long npos = nodes[pos].nxt[c];
        if (npos == -1) continue;
        long long p = nodes[pos].fail;
        while (nodes[p].nxt[c] == -1) p = nodes[p].fail;
        long long fpos = next(nodes[pos].fail, c);
        nodes[npos].fail = fpos;
        if (nodes[fpos].matched) nodes[pos].matched = true;
        que.push(npos);
      }
    }
  }
  Node& operator[](long long pos) { return nodes[pos]; }
  Node operator[](long long pos) const { return nodes[pos]; }
};
string s;
long long x;
vector<string> ps;
bool judge(string t) {
  long long n = (long long)t.size();
  for (long long l = 0; l < n; ++l) {
    long long sum = 0;
    for (long long r = l; r < n; ++r) {
      sum += t[r] - '0';
      if (sum != x and x % sum == 0) {
        return true;
      }
    }
  }
  return false;
}
void dfs(string& t, long long num) {
  if (num == x and !judge(t)) ps.push_back(t);
  for (long long d = 1; d <= 9 and num + d <= x; ++d) {
    t.push_back('0' + d);
    dfs(t, num + d);
    t.pop_back();
  }
}
void solve() {
  cin >> s >> x;
  string tmp = "";
  dfs(tmp, 0);
  PatternMatching<9, char> pm('1');
  for (auto p : ps) pm.add(p);
  pm.build();
  long long n = (long long)pm.nodes.size();
  vector<long long> dp(n, INF);
  vector<long long> ndp(n, INF);
  dp[0] = 0;
  for (char c : s) {
    ndp.assign(n, INF);
    for (long long pos = 0; pos < n; ++pos) {
      chmin(ndp[pos], dp[pos] + 1);
      long long npos = pm.next(pos, pm.enc(c));
      if (!pm[npos].matched) {
        chmin(ndp[npos], dp[pos]);
      }
    }
    swap(ndp, dp);
  }
  cout << *min_element(dp.begin(), dp.end()) << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
