#include <bits/stdc++.h>
using namespace std;
const int N = 1007;
int n, x;
short dp[N][11001];
char s[N];
vector<vector<int> > state;
vector<vector<int> > G;
map<vector<int>, int> vec2index;
bool is_vaild_seg(vector<int> V) {
  if ((int)V.size() == 0) return true;
  vector<int> sum = V;
  int tot = V[0];
  for (int i = 1; i < (int)sum.size(); i++) {
    sum[i] += sum[i - 1];
    tot = sum[i];
  }
  if (tot != x) return true;
  for (int i = 0; i < (int)V.size(); i++) {
    for (int j = i; j < (int)V.size(); j++) {
      int val = sum[j];
      if (i > 0) val -= sum[i - 1];
      if (val != tot && tot % val == 0) return true;
    }
  }
  return false;
}
bool is_vaild_state(vector<int> V) {
  for (int i = 0; i < (int)V.size(); i++) {
    for (int j = i; j < (int)V.size(); j++) {
      vector<int> seg;
      for (int k = i; k <= j; k++) {
        seg.push_back(V[k]);
      }
      if (!is_vaild_seg(seg)) return false;
    }
  }
  return true;
}
void get_each_state(vector<int> V, int sum) {
  if (sum > x) return;
  if (is_vaild_state(V)) state.push_back(V);
  for (int i = 2; i <= 9; i++) {
    vector<int> nxt_v = V;
    nxt_v.push_back(i);
    get_each_state(nxt_v, sum + i);
  }
}
int get_next_state(int now, int value) {
  vector<int> v = state[now];
  v.push_back(value);
  int sum = 0;
  for (auto &val : v) sum += val;
  int pos = 0;
  while (sum > x && pos < (int)v.size()) sum -= v[pos], pos++;
  vector<int> nv;
  while (pos < (int)v.size()) nv.push_back(v[pos]), pos++;
  if (vec2index.find(nv) != vec2index.end()) return vec2index[nv];
  return -1;
}
void prepare() {
  get_each_state(vector<int>(), 0);
  G.resize((int)state.size());
  for (int i = 0; i < (int)state.size(); i++) {
    vec2index[state[i]] = i;
    G[i].resize(10, -1);
  }
  for (int i = 0; i < (int)state.size(); i++) {
    G[i][1] = x == 1 ? -1 : 0;
    for (int j = 2; j <= 9; j++) {
      G[i][j] = get_next_state(i, j);
    }
  }
}
void solve() {
  scanf("%s%d", s + 1, &x);
  prepare();
  n = strlen(s + 1);
  memset(dp, -1, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < (int)state.size(); j++) {
      if (dp[i][j] == -1) continue;
      if (dp[i + 1][j] == -1)
        dp[i + 1][j] = dp[i][j] + 1;
      else
        dp[i + 1][j] = min((int)dp[i + 1][j], dp[i][j] + 1);
      int k = G[j][s[i + 1] - '0'];
      if (k == -1) continue;
      if (dp[i + 1][k] == -1)
        dp[i + 1][k] = dp[i][j];
      else
        dp[i + 1][k] = min(dp[i + 1][k], dp[i][j]);
    }
  }
  int ans = n;
  for (int i = 0; i < (int)state.size(); i++) {
    if (~dp[n][i]) ans = min(ans, (int)dp[n][i]);
  }
  printf("%d\n", ans);
}
int main() {
  int NT = 1;
  while (NT--) solve();
  return 0;
}
