#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 1e3 + 10, maxm = 3e4 + 10, lg = 10, mod = 998244353,
          inf = 1e18;
string s;
int x, C[maxm][lg], first[maxm], nxt[maxm][lg], ts, dp[2][maxm];
bool bad[maxm];
inline void addtrie(string t) {
  int v = 0;
  for (auto c : t) {
    if (C[v][c - '0'] == 0) C[v][c - '0'] = ++ts;
    v = C[v][c - '0'];
  }
  bad[v] = 1;
}
inline void shaho() {
  queue<int> q;
  for (int i = 1; i < lg; i++)
    if (C[0][i]) q.push(nxt[0][i] = C[0][i]);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 1; i < lg; i++) {
      if (!C[v][i])
        nxt[v][i] = nxt[first[v]][i];
      else {
        q.push(nxt[v][i] = C[v][i]);
        first[C[v][i]] = nxt[first[v]][i];
      }
    }
  }
}
void brute(int sum = 0, string t = "") {
  if (sum > x) return;
  if (sum == x) {
    for (int l = 0; l < (int)(t.size()); l++) {
      int tmp = 0;
      for (int r = l; r < (int)(t.size()); r++) {
        tmp += t[r] - '0';
        if (tmp != x && x % tmp == 0) return;
      }
    }
    return addtrie(t);
  }
  for (int i = 1; i <= 9; i++) brute(sum + i, t + char('0' + i));
}
inline void mini(int &x, int y) {
  if (x > y) x = y;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> x;
  brute(), shaho();
  memset(dp, 69, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < (int)(s.size()); i++) {
    bool b = i & 1;
    for (int j = 0; j <= ts; j++)
      if (!bad[j]) {
        mini(dp[b ^ 1][j], dp[b][j] + 1);
        mini(dp[b ^ 1][nxt[j][s[i] - '0']], dp[b][j]);
        dp[b][j] = mod;
      }
  }
  int ans = (int)(s.size());
  for (int i = 0; i <= ts; i++)
    if (!bad[i]) ans = min(ans, dp[(int)(s.size()) & 1][i]);
  cout << ans;
  return 0;
}
