#include <bits/stdc++.h>
using namespace std;
struct vertex {
  map<char, int> next, go;
  int p, link;
  char pch;
  vector<int> leaf;
  vertex(int p = -1, char pch = -1) : p(p), pch(pch), link(-1) {}
};
vector<vertex> t;
void aho_init() {
  t.clear();
  t.push_back(vertex());
}
void add_string(string &s, int id) {
  int v = 0;
  for (char c : s) {
    if (!t[v].next.count(c)) {
      t[v].next[c] = t.size();
      t.push_back(vertex(v, c));
    }
    v = t[v].next[c];
  }
  t[v].leaf.push_back(id);
}
int go(int v, char c);
int get_link(int v) {
  if (t[v].link < 0)
    if (!v || !t[v].p)
      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 c) {
  if (!t[v].go.count(c))
    if (t[v].next.count(c))
      t[v].go[c] = t[v].next[c];
    else
      t[v].go[c] = v == 0 ? 0 : go(get_link(v), c);
  return t[v].go[c];
}
int x;
void buildBadStrings(string &str, int sum) {
  if (sum > x) return;
  if (sum == x) {
    bool bad = true;
    int n = ((int)str.size());
    for (int i = (0); i < (n); i++) {
      int acum = 0;
      for (int j = (i); j < (n); j++) {
        acum += str[j] - '0';
        if (acum < x && x % acum == 0) {
          bad = false;
          break;
        }
      }
      if (!bad) break;
    }
    if (bad) add_string(str, 0);
    return;
  }
  for (int i = (1); i < (10); i++) {
    str.push_back('0' + i);
    buildBadStrings(str, sum + i);
    str.pop_back();
  }
}
int dp[1000][5000];
string s;
int solve(int pos, int node) {
  if (((int)t[node].leaf.size())) return 1e5;
  if (pos == ((int)s.size())) return 0;
  if (dp[pos][node] != -1) return dp[pos][node];
  int ret = solve(pos + 1, node) + 1;
  ret = min(ret, solve(pos + 1, go(node, s[pos])));
  return dp[pos][node] = ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> x;
  aho_init();
  string aux = "";
  buildBadStrings(aux, 0);
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0) << '\n';
  return 0;
}
