#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,-ffloat-store")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
using namespace std;
const int maxn = 1005;
string s;
int c, n, a[maxn], x[25], root, cur;
int trie[maxn * 5][10], go[maxn * 5][10], link[maxn * 5];
int dp[maxn][maxn * 5];
bool terminal[maxn * 5];
void readf() {
  cin >> s >> c;
  n = s.size();
  s = " " + s;
  for (int i = 1; i <= n; ++i) a[i] = s[i] - '0';
}
void trys(int i, int cost) {
  if (cost == 0) {
    for (int u = 1; u < i; ++u) {
      int sum = 0;
      for (int v = u; v < i; ++v) {
        sum += x[v];
        if (sum < c && c % sum == 0) return;
      }
    }
    int p = root;
    for (int u = 1; u < i; ++u) {
      if (trie[p][x[u]] == -1) trie[p][x[u]] = ++cur;
      p = trie[p][x[u]];
    }
    terminal[p] = 1;
    return;
  }
  for (int j = 1; j < 10; ++j)
    if (cost >= j) {
      x[i] = j;
      trys(i + 1, cost - j);
    }
}
void build() {
  queue<int> qu;
  link[0] = 0;
  qu.push(0);
  while (qu.size() > 0) {
    int u = qu.front();
    qu.pop();
    for (int i = 0; i < 10; ++i) {
      go[u][i] = go[link[u]][i];
      if (trie[u][i] != -1) {
        link[trie[u][i]] = go[u][i];
        go[u][i] = trie[u][i];
        qu.push(trie[u][i]);
      }
    }
  }
}
void solve() {
  memset(trie, -1, sizeof(trie));
  memset(dp, 0x3f, sizeof(dp));
  root = 0;
  cur = 0;
  trys(1, c);
  build();
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= cur; ++j) dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
    for (int j = 0; j <= cur; ++j) {
      int nxj = go[j][a[i]];
      if (nxj == -1 || terminal[nxj] == 1) continue;
      dp[i][nxj] = min(dp[i][nxj], dp[i - 1][j]);
    }
  }
  int ans = n;
  for (int j = 0; j <= cur; ++j) ans = min(ans, dp[n][j]);
  cout << ans << '\n';
}
int main() {
  srand(time(NULL));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  readf();
  solve();
}
