#include <bits/stdc++.h>
using namespace std;
struct AC {
  static const int K = 1 << 8;
  struct node {
    int nxt[K], go[K], link, leaf, par;
    char pch;
    node(int par = -1, char pch = '$') : par(par), pch(pch) {
      fill(begin(nxt), end(nxt), -1);
      fill(begin(go), end(go), -1);
      leaf = false;
      link = -1;
    }
  };
  vector<node> tree;
  AC() { tree.resize(1); }
  int add(string str) {
    int ptr = 0;
    for (auto ch : str) {
      if (tree[ptr].nxt[ch] == -1) {
        tree[ptr].nxt[ch] = tree.size();
        tree.push_back(node(ptr, ch));
      }
      ptr = tree[ptr].nxt[ch];
    }
    tree[ptr].leaf = true;
    return ptr;
  }
  int get_link(int v) {
    if (tree[v].link == -1) {
      if (v == 0 || tree[v].par == 0) {
        tree[v].link = 0;
      } else {
        tree[v].link = go(get_link(tree[v].par), tree[v].pch);
      }
    }
    return tree[v].link;
  }
  int go(int v, char ch) {
    if (tree[v].go[ch] == -1) {
      if (tree[v].nxt[ch] != -1) {
        tree[v].go[ch] = tree[v].nxt[ch];
      } else {
        tree[v].go[ch] = (v == 0) ? 0 : go(get_link(v), ch);
      }
    }
    return tree[v].go[ch];
  }
} ac;
int chk(string str, int x) {
  for (int i = 0; i < str.size(); i++) {
    int sum = 0;
    for (int j = i; j < str.size(); j++) {
      sum += str[j] - '0';
      if (x % sum == 0 && x != sum) return 1;
    }
  }
  return 0;
}
int xx;
void genarate(int x, string s) {
  if (!x) {
    if (!chk(s, xx)) {
      ac.add(s);
    }
    return;
  }
  for (int i = 1; i < 10; i++)
    if (x >= i) {
      genarate(x - i, s + string(1, char(i + '0')));
    }
}
string str;
int dp[1001][15000], leaf[15000];
vector<int> adj[15000];
void dfs(int v, int c = 0) {
  c |= ac.tree[v].leaf;
  leaf[v] = c;
  for (int u : adj[v]) {
    dfs(u, c);
  }
}
int f(int idx, int v) {
  if (idx >= str.size()) return 0;
  if (~dp[idx][v]) return dp[idx][v];
  int res = 1 + f(idx + 1, v);
  if (!leaf[ac.go(v, str[idx])]) res = min(res, f(idx + 1, ac.go(v, str[idx])));
  return dp[idx][v] = res;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> str >> xx;
  memset(dp, -1, sizeof dp);
  genarate(xx, "");
  for (int i = 1; i < ac.tree.size(); i++) {
    adj[ac.get_link(i)].push_back(i);
  }
  dfs(0);
  cout << f(0, 0) << endl;
}
