#include <bits/stdc++.h>
using namespace std;
struct aho_corasick {
  static const int K = 10;
  struct Vertex {
    int next[K];
    bool leaf = false;
    int p = -1;
    char pch;
    int link = -1;
    int go[K];
    Vertex(int p = -1, char ch = '#') : p(p), pch(ch) {
      fill(begin(next), end(next), -1);
      fill(begin(go), end(go), -1);
    }
  };
  vector<Vertex> t;
  void init() {
    t.clear();
    t.push_back(Vertex());
  }
  void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
      int c = ch - '0';
      if (t[v].next[c] == -1) {
        t[v].next[c] = t.size();
        t.emplace_back(v, ch);
      }
      v = t[v].next[c];
    }
    t[v].leaf = 1;
  }
  int get_link(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else
        t[v].link = go(get_link(t[v].p), t[v].pch);
    }
    return t[v].link;
  }
  int go(int v, char ch) {
    int c = ch - '0';
    if (t[v].go[c] == -1) {
      if (t[v].next[c] != -1)
        t[v].go[c] = t[v].next[c];
      else
        t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
  }
} aho;
int x;
string s;
vector<string> v;
void rec(string& s) {
  int sum = 0;
  int l = s.length();
  for (int i = l - 1; i >= 0; i--) sum += s[i] - '0';
  if (sum == x) {
    for (int i = 0; i < l; i++) {
      int tmp = 0;
      for (int j = i; j < l; j++) {
        tmp += s[j] - '0';
        if (x % tmp == 0 && tmp != x) return;
      }
    }
    v.emplace_back(s);
    return;
  }
  if (sum > x) return;
  for (int i = 1; i <= 9; i++) {
    s += i + '0';
    rec(s);
    s.pop_back();
  }
}
int dp[1005][5005];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> s >> x;
  string t;
  rec(t);
  aho.init();
  for (int i = 0; i < v.size(); i++) aho.add_string(v[i]);
  int m = aho.t.size();
  int l = s.length();
  for (int i = 0; i <= l; i++)
    for (int j = 0; j < m; j++) dp[i][j] = 1e9;
  dp[0][0] = 0;
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < m; j++) {
      if (dp[i][j] == 1e9) continue;
      int k = aho.go(j, s[i]);
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
      if (!aho.t[k].leaf) dp[i + 1][k] = min(dp[i + 1][k], dp[i][j]);
    }
  }
  int ans = 1e9;
  for (int j = 0; j < m; j++) ans = min(ans, dp[l][j]);
  printf("%d\n", ans);
}
