#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
int tree[MAXN][10], fail[MAXN], word[MAXN], cnt;
void Init() {
  for (int i = 0; i <= cnt; i++) {
    word[i] = fail[i] = 0;
    memset(tree[i], 0, sizeof(tree[i]));
  }
  cnt = 0;
}
void Insert(string s) {
  int root = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    int id = s[i] - '0';
    if (!tree[root][id]) tree[root][id] = ++cnt;
    root = tree[root][id];
  }
  word[root] = 1;
}
void get_fail() {
  queue<int> q;
  for (int i = 0; i < 10; i++)
    if (tree[0][i]) {
      fail[tree[0][i]] = 0;
      q.push(tree[0][i]);
    }
  while (!q.empty()) {
    int rt = q.front();
    q.pop();
    for (int i = 0; i < 10; i++) {
      if (tree[rt][i]) {
        fail[tree[rt][i]] = tree[fail[rt]][i];
        word[tree[rt][i]] += word[fail[tree[rt][i]]];
        q.push(tree[rt][i]);
      } else
        tree[rt][i] = tree[fail[rt]][i];
    }
  }
}
string s;
int x, tot;
void dfs(string str, int sum) {
  if (sum == x) {
    for (int i = 0; i < (int)str.size(); i++) {
      for (int j = i, cal = 0; j < (int)str.size(); j++) {
        cal += str[j] - '0';
        if (cal < x && x % cal == 0) return;
      }
    }
    Insert(str);
  } else
    for (int i = 1; i <= 9 && i + sum <= x; i++)
      dfs(str + char('0' + i), sum + i);
}
int main(void) {
  Init();
  cin >> s >> x;
  dfs("", 0);
  get_fail();
  vector<int> dp(cnt, s.size());
  dp[0] = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    vector<int> tp(cnt, s.size());
    for (int j = 0; j < cnt; j++) {
      tp[j] = min(tp[j], dp[j] + 1);
      if (!word[tree[j][s[i] - '0']])
        tp[tree[j][s[i] - '0']] = min(tp[tree[j][s[i] - '0']], dp[j]);
    }
    swap(dp, tp);
  }
  int ans = s.size();
  for (int i = 0; i < cnt; i++) ans = min(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
