#include <bits/stdc++.h>
using namespace std;
vector<string> ss;
string inputs;
int x;
void dfs(string s, int sum) {
  if (sum == x) {
    for (int i = 0; i < s.length(); i++) {
      int tmp = 0;
      for (int j = i; j < s.length(); j++) {
        tmp += s[j] - '0';
        if (tmp != x && x % tmp == 0) {
          return;
        }
      }
    }
    ss.push_back(s);
    return;
  }
  int kp = x - sum;
  for (int i = 1; i <= min(kp, 9); i++) {
    dfs(s + (char)('0' + i), sum + i);
  }
  return;
}
int trie[5005][10];
int fail[5005];
int flag[5005];
int tot;
void trieinsert(string str) {
  int len = str.length();
  int rt = 0;
  for (int i = 0; i < len; i++) {
    int id = str[i] - '0';
    if (!trie[rt][id]) {
      trie[rt][id] = ++tot;
    }
    rt = trie[rt][id];
  }
  flag[rt]++;
}
void getfail() {
  queue<int> que;
  fail[0] = 0;
  for (int i = 1; i < 10; i++) {
    if (trie[0][i]) {
      fail[trie[0][i]] = 0;
      que.push(trie[0][i]);
    }
  }
  while (!que.empty()) {
    int rt = que.front();
    que.pop();
    if (flag[fail[rt]]) flag[rt]++;
    for (int i = 1; i < 10; i++) {
      if (!trie[rt][i]) {
        trie[rt][i] = trie[fail[rt]][i];
      } else {
        fail[trie[rt][i]] = trie[fail[rt]][i];
        que.push(trie[rt][i]);
      }
    }
  }
}
int dp[1005][5005];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> inputs;
  cin >> x;
  dfs("", 0);
  for (int i = 0; i < ss.size(); i++) {
    trieinsert(ss[i]);
  }
  getfail();
  for (int i = 0; i <= inputs.length(); i++) {
    for (int j = 0; j <= tot; j++) {
      dp[i][j] = 1000000;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i < inputs.length(); i++) {
    for (int j = 0; j <= tot; j++) {
      dp[i + 1][j] = min(dp[i][j] + 1, dp[i + 1][j]);
      if (flag[trie[j][inputs[i] - '0']] == 0)
        dp[i + 1][trie[j][inputs[i] - '0']] =
            min(dp[i + 1][trie[j][inputs[i] - '0']], dp[i][j]);
    }
  }
  int ans = 1000000;
  for (int i = 0; i <= tot; i++) {
    ans = min(ans, dp[inputs.length()][i]);
  }
  cout << ans << endl;
  return 0;
}
