#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 500;
int T;
char str[1500];
int n, a[1500];
struct Acautomaton {
  int ch[10009][11], val[10009], f[10009], sz;
  void init() { sz = 0; }
  void insert(vector<int> vv) {
    int u = 0, len = vv.size();
    for (int i = 0; i < len; i++) {
      int j = vv[i];
      if (!ch[u][j]) {
        ch[u][j] = ++sz;
      }
      u = ch[u][j];
    }
    val[u] = 1;
  }
  void getfail() {
    int u = 0;
    queue<int> q;
    for (int i = 0; i < 10; i++)
      if (ch[u][i]) {
        q.push(ch[u][i]);
      }
    while (!q.empty()) {
      int r = q.front();
      q.pop();
      for (int c = 0; c < 10; ++c) {
        u = ch[r][c];
        if (!u) {
          ch[r][c] = ch[f[r]][c];
          continue;
        }
        q.push(u);
        int v = f[r];
        while (v && !ch[v][c]) v = f[v];
        f[u] = ch[v][c];
        val[u] |= val[f[u]];
      }
    }
  }
} ac;
void dfs(int s, vector<int> cnt) {
  if (s == n) {
    int sz = cnt.size();
    for (int i = 0; i < sz; i++) {
      int tmp = 0;
      for (int j = i; j < sz; j++) {
        tmp += cnt[j];
        if (tmp != n && n % tmp == 0) return;
      }
    }
    ac.insert(cnt);
    return;
  }
  for (int i = 1; i < 10 && s + i <= n; i++) {
    cnt.push_back(i);
    dfs(s + i, cnt);
    cnt.pop_back();
  }
}
int dp[1300][10009];
int main() {
  ac.init();
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  for (int i = 1; i <= len; i++) a[i] = str[i] - '0';
  scanf("%d", &n);
  dfs(0, {});
  ac.getfail();
  memset(dp, 0x3f, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= len; i++) {
    for (int j = 0; j <= ac.sz; j++) {
      int to = ac.ch[j][a[i]];
      if (!ac.val[to]) dp[i][to] = min(dp[i][to], dp[i - 1][j]);
      dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i <= ac.sz; i++) ans = min(ans, dp[len][i]);
  printf("%d\n", ans);
  return 0;
}
