#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 5000;
const int M = 1e3 + 6;
int trie[N][10], fail[N], tc, tl, n, f[M][N];
bool en[N];
char s[N];
int t[N];
void insert() {
  int now = 0;
  for (int i = 1, c; i <= tl; i++) {
    c = t[i];
    if (trie[now][c] == 0) trie[now][c] = ++tc;
    now = trie[now][c];
  }
  en[now] = 1;
}
void build() {
  queue<int> q;
  for (int i = 1; i < 10; i++)
    if (trie[0][i]) q.push(trie[0][i]);
  while (!q.empty()) {
    int now = q.front();
    en[now] |= en[fail[now]];
    q.pop();
    for (int i = 1; i < 10; i++) {
      if (trie[now][i]) {
        q.push(trie[now][i]);
        fail[trie[now][i]] = trie[fail[now]][i];
      } else
        trie[now][i] = trie[fail[now]][i];
    }
  }
}
bool check() {
  for (int i = 1; i <= tl; i++) {
    int sum = t[i];
    if (sum != n && n % sum == 0) return true;
    for (int j = i + 1; j <= tl; j++) {
      sum += t[j];
      if (sum != n && n % sum == 0) return true;
    }
  }
  return false;
}
int cnt = 0;
void dfs(int now) {
  if (now == 0) {
    if (check()) return;
    insert();
    return;
  }
  for (int i = 1; i <= 9; i++) {
    if (i <= now) {
      t[++tl] = i;
      dfs(now - i);
      tl--;
    }
  }
}
signed main() {
  scanf("%s %d", s + 1, &n);
  dfs(n);
  build();
  int len = strlen(s + 1), now = 0;
  memset(f, 0x3f, sizeof f);
  f[0][0] = 0;
  for (int i = 0; i < len; i++)
    for (int j = 0; j <= tc; j++) {
      f[i + 1][j] = min(f[i + 1][j], f[i][j] + 1);
      if (!en[trie[j][s[i + 1] - '0']])
        f[i + 1][trie[j][s[i + 1] - '0']] =
            min(f[i + 1][trie[j][s[i + 1] - '0']], f[i][j]);
    }
  int ans = 0x3f3f3f3f;
  for (int i = 0; i <= tc; i++) ans = min(ans, f[len][i]);
  cout << ans;
  return 0;
}
