#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int nxt[maxn * 500][10], fail[maxn * 500], isend[maxn * 500], o = 0;
void insert(int* a) {
  int rt = 0;
  for (int i = 1; i <= a[0]; i++) {
    int c = a[i];
    if (nxt[rt][c] == 0) nxt[rt][c] = ++o;
    rt = nxt[rt][c];
  }
  isend[rt] = 1;
}
void build() {
  queue<int> Q;
  for (int i = 1; i <= 9; i++) {
    if (nxt[0][i] != 0) {
      fail[nxt[0][i]] = 0;
      Q.push(nxt[0][i]);
    }
  }
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 1; i <= 9; i++) {
      if (nxt[x][i]) {
        fail[nxt[x][i]] = nxt[fail[x]][i];
        Q.push(nxt[x][i]);
      } else
        nxt[x][i] = nxt[fail[x]][i];
    }
  }
}
int a[maxn], X;
void dfs(int pos, int now) {
  if (now > X) return;
  if (now == X) {
    a[0] = pos - 1;
    for (int i = 1; i < pos; i++) {
      int tmp = 0;
      for (int j = 1; j <= i; j++) tmp += a[j];
      if (tmp != X && X % tmp == 0) return;
      for (int j = i + 1; j < pos; j++) {
        tmp -= a[j - i];
        tmp += a[j];
        if (tmp != X && X % tmp == 0) return;
      }
    }
    insert(a);
    return;
  }
  for (int i = 1; i <= 9; i++) {
    a[pos] = i;
    dfs(pos + 1, now + i);
  }
}
char s[maxn];
int dp[maxn * 50][maxn];
int main(void) {
  o = 0;
  scanf("%s%d", s + 1, &X);
  int n = strlen(s + 1);
  dfs(1, 0);
  build();
  memset(dp, 0x3f3f3f3f, sizeof dp);
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    int c = s[i] - '0';
    for (int j = 0; j <= o; j++) {
      if (isend[j]) continue;
      dp[nxt[j][c]][i] = min(dp[nxt[j][c]][i], dp[j][i - 1]);
      dp[j][i] = min(dp[j][i], dp[j][i - 1] + 1);
    }
  }
  int ans = n;
  for (int i = 0; i <= o; i++)
    if (isend[i] == 0) ans = min(ans, dp[i][n]);
  printf("%d\n", ans);
}
