#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int N = 5005;
string s;
int x;
int g[N][10], f[N], en[N], cnt = 1;
vector<string> kek;
int dp[N][N];
bool chk(string tpa) {
  for (int i = 0, _c = tpa.size() - 1; i <= _c; ++i) {
    int tot = 0;
    for (int j = i, _c = tpa.size() - 1; j <= _c; ++j) {
      tot += (tpa[j] - '0');
      if (x % tot == 0 && (tot < x)) return false;
    }
  }
  return true;
}
void add(string &x) {
  int j = 1;
  for (auto &v : x) {
    int t = v - '0';
    if (!g[j][t]) g[j][t] = ++cnt;
    j = g[j][t];
  }
  en[j] = 1;
}
void build_aho() {
  queue<int> q;
  for (int i = 1, _c = 9; i <= _c; ++i) {
    if (g[1][i]) {
      f[g[1][i]] = 1;
      q.push(g[1][i]);
    } else
      g[1][i] = 1;
  }
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = 1, _c = 9; i <= _c; ++i)
      if (g[u][i]) {
        int v = g[u][i];
        int t = f[u];
        while (!g[t][i]) t = f[t];
        t = g[t][i];
        f[v] = t;
        q.push(v);
      }
  }
}
int nex(int i, int j) {
  while (!g[i][j]) {
    i = f[i];
  }
  i = g[i][j];
  return i;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  if (fopen("TASK"
            ".inp",
            "r"))
    freopen(
        "TASK"
        ".inp",
        "r", stdin);
  cin >> s >> x;
  int n = s.size();
  function<void(string, int)> dfs = [&](string _, int p) {
    if (p > x) return;
    if (p == x) {
      if (chk(_)) kek.push_back(_);
    }
    for (int i = 1, _c = 9; i <= _c; ++i) dfs(_ + (char)(i + '0'), p + i);
  };
  dfs("", 0);
  for (auto &v : kek) add(v);
  build_aho();
  memset(dp, 127, sizeof(dp));
  dp[0][1] = 0;
  for (int i = 1, _c = n; i <= _c; ++i) {
    for (int j = 1, _c = cnt; j <= _c; ++j)
      dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
    for (int j = 1, _c = cnt; j <= _c; ++j) {
      int u = nex(j, s[i - 1] - '0');
      if (!u || en[u]) continue;
      dp[i][u] = min(dp[i][u], dp[i - 1][j]);
    }
  }
  int ans = n;
  for (int i = 1, _c = cnt; i <= _c; ++i) ans = min(ans, dp[n][i]);
  cout << ans << '\n';
}
