#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pid = pair<int, double>;
using pdd = pair<double, double>;
using pic = pair<int, char>;
using pllll = pair<ll, ll>;
using pllc = pair<ll, char>;
using pill = pair<int, ll>;
using pss = pair<string, string>;
using pis = pair<int, string>;
using plls = pair<ll, string>;
using plld = pair<ll, double>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<ll>;
const int AL = 9;
int x;
string s;
string t;
struct node {
  int next[AL];
  bool leaf;
  int p;
  char pch;
  int go[AL];
  int link;
  node() {
    memset(next, -1, sizeof(next));
    memset(go, -1, sizeof(go));
    leaf = false;
    link = p = -1;
  }
  int& operator[](int x) { return next[x]; }
};
vector<node> trie;
void add_string(string t) {
  int v = 0;
  for (int i = 0; i < t.size(); i++) {
    int c = t[i] - '1';
    if (trie[v][c] == -1) {
      trie.push_back(node());
      trie[trie.size() - 1].p = v;
      trie[trie.size() - 1].pch = c;
      trie[v][c] = trie.size() - 1;
    }
    v = trie[v][c];
  }
  trie[v].leaf = true;
}
int get_link(int v);
int go(int v, int c) {
  if (trie[v].go[c] == -1) {
    if (trie[v][c] != -1) {
      trie[v].go[c] = trie[v][c];
    } else {
      trie[v].go[c] = (v == 0) ? 0 : go(get_link(v), c);
    }
  }
  return trie[v].go[c];
}
int get_link(int v) {
  if (trie[v].link == -1) {
    if (v == 0 || trie[v].p == 0) {
      trie[v].link = 0;
    } else {
      trie[v].link = go(get_link(trie[v].p), trie[v].pch);
    }
  }
  return trie[v].link;
}
void brute(int i, int sum) {
  if (sum == x) {
    bool ok = true;
    for (int l = 0; l < t.size(); l++) {
      int curr = 0;
      for (int r = l; r < t.size(); r++) {
        curr += (t[r] - '0');
        if (x % curr == 0 && curr != x) {
          ok = false;
        }
      }
    }
    if (ok) {
      add_string(t);
    }
    return;
  }
  for (int j = 1; j <= min(x - sum, 9); j++) {
    t += '0' + j;
    brute(i + 1, sum + j);
    t.pop_back();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> s >> x;
  trie.push_back(node());
  brute(0, 0);
  vector<vi> dp(s.size() + 1, vi(trie.size(), 1e9));
  dp[0][0] = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < trie.size(); j++) {
      if (dp[i][j] != 1e9) {
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
        int nxt = go(j, s[i] - '1');
        if (!trie[nxt].leaf) {
          dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j]);
        }
      }
    }
  }
  cout << *min_element(dp[s.size()].begin(), dp[s.size()].end());
  return 0;
}
