#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
string s;
int x, tr[15000][20], e[15000], fail[15000], dp[1010][15000], len = 0,
                                                              ans = 1e9;
vector<string> v;
queue<int> q;
void dfs(string t, int sum) {
  if (sum == x) {
    int ok = 1;
    for (int i = 0; i < t.size(); i++) {
      int cur = 0;
      for (int j = i; j < t.size(); j++) {
        cur += t[j] - '0';
        if (cur != sum && sum % cur == 0) {
          ok = 0;
          break;
        }
      }
      if (ok == 0) break;
    }
    if (ok) v.push_back(t);
    return;
  }
  for (int i = 1; i <= 9; i++)
    if (sum + 1 <= x) dfs(t + (char)(i + '0'), sum + i);
}
void ins(string t) {
  int u = 0;
  for (int i = 0; i < t.size(); i++) {
    if (tr[u][t[i] - '0'] > 0)
      u = tr[u][t[i] - '0'];
    else
      u = tr[u][t[i] - '0'] = ++len;
  }
  e[u]++;
}
void build() {
  for (int i = 1; i <= 9; i++)
    if (tr[0][i] > 0) q.push(tr[0][i]);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    e[u] += e[fail[u]];
    for (int i = 1; i <= 9; i++) {
      if (tr[u][i] > 0) {
        fail[tr[u][i]] = tr[fail[u]][i];
        q.push(tr[u][i]);
      } else
        tr[u][i] = tr[fail[u]][i];
    }
  }
}
int main() {
  cin >> s >> x;
  dfs("", 0);
  for (int i = 0; i < v.size(); i++) ins(v[i]);
  build();
  for (int i = 0; i < 1005; i++)
    for (int j = 0; j < 14000; j++) dp[i][j] = 1e9;
  dp[0][0] = 0;
  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < len + 1; j++) {
      if (dp[i][j] == 1e9) continue;
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
      int j2 = tr[j][s[i] - '0'];
      if (e[j2] == 0) dp[i + 1][j2] = min(dp[i + 1][j2], dp[i][j]);
    }
  for (int i = 0; i < len + 1; i++) ans = min(ans, dp[s.size()][i]);
  cout << ans << endl;
  return 0;
}
