#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const int N = 1024;
const int M = 2e5;
int n, x;
char s[N];
vector<int> g;
bool mark[M];
int cnt, fail[M], go[M][10];
void add() {
  int v = 0;
  for (auto x : g) {
    if (!go[v][x]) go[v][x] = ++cnt;
    v = go[v][x];
  }
  mark[v] = true;
}
queue<int> q;
void build() {
  q.push(0);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 1; i <= 9; ++i) {
      if (go[v][i]) {
        q.push(go[v][i]);
        fail[go[v][i]] = v ? go[fail[v]][i] : 0;
      } else
        go[v][i] = go[fail[v]][i];
    }
  }
}
void generate(int sum) {
  if (sum == x) {
    for (int l = 0; l <= (int)g.size() - 1; ++l) {
      int s = 0;
      for (int r = l; r <= (int)g.size() - 1; ++r) {
        s += g[r];
        if (x != s && x % s == 0) return;
      }
    }
    add();
    return;
  }
  for (int i = 1; i <= min(9, x - sum); ++i) {
    g.push_back(i);
    generate(sum + i);
    g.pop_back();
  }
}
int dp[M], ndp[M];
int main() {
  scanf("%s%d", s + 1, &x);
  n = strlen(s + 1);
  generate(0);
  build();
  fill(dp + 1, dp + M, n);
  for (int i = 1; i <= n; ++i) {
    int c = s[i] - '0';
    fill(ndp, ndp + M, n);
    for (int j = 0; j <= cnt; ++j) {
      if (!mark[go[j][c]]) ndp[go[j][c]] = min(ndp[go[j][c]], dp[j]);
      ndp[j] = min(ndp[j], dp[j] + 1);
    }
    swap(dp, ndp);
  }
  int ans = n;
  for (int j = 0; j <= cnt; ++j) ans = min(ans, dp[j]);
  printf("%d\n", ans);
  return 0;
}
