#include <bits/stdc++.h>
using namespace std;
namespace dfs {
bool chk[100];
int a[100];
vector<int> cb[10000];
int can[10], num = 0;
int tot = 0;
inline void dfs(int x, int l, int left) {
  if (x == l + 1) {
    if (left != 0) return;
    int res = 0;
    for (int i = 1; i <= l; i++) {
      res = a[i];
      for (int j = i + 1; j <= l; j++) {
        res += a[j];
        if (chk[res]) return;
      }
    }
    tot++;
    for (int i = 1; i <= l; i++) cb[tot].push_back(a[i]);
    return;
  }
  for (int i = 1; i <= num; i++) {
    if (can[i] > left) break;
    a[x] = can[i];
    dfs(x + 1, l, left - a[x]);
  }
}
}  // namespace dfs
int x;
int tot = 0;
int tr[20000][13];
int endp[20000];
inline void insert(const vector<int> &x) {
  int u = 0;
  for (int i = 0; i < x.size(); i++) {
    if (tr[u][x[i]] == 0) tr[u][x[i]] = ++tot;
    u = tr[u][x[i]];
  }
  endp[u] = 1;
}
queue<int> q;
int fail[200000];
int dp[1100][8000];
char ss[1100];
int s[1100], n;
int main() {
  scanf("%s", ss + 1);
  n = strlen(ss + 1);
  for (int i = 1; i <= n; i++) s[i] = ss[i] - '0';
  cin >> x;
  for (int i = 1; i < x; i++)
    if (x % i == 0) dfs::chk[i] = 1;
  for (int i = 1; i <= min(x - 1, 9); i++)
    if (x % i != 0) dfs::can[++dfs::num] = i;
  if (x <= 9) dfs::tot++, dfs::cb[dfs::tot].push_back(x);
  for (int l = 1; l <= x / 2; l++) {
    dfs::dfs(1, l, x);
  }
  for (int i = 1; i <= dfs::tot; i++) {
    insert(dfs::cb[i]);
  }
  for (int i = 1; i <= 9; i++)
    if (tr[0][i]) q.push(tr[0][i]);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 1; i <= 9; i++) {
      if (tr[x][i])
        fail[tr[x][i]] = tr[fail[x]][i], q.push(tr[x][i]);
      else
        tr[x][i] = tr[fail[x]][i];
    }
  }
  memset(dp, 63, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= tot; j++) {
      if (endp[j]) continue;
      dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
      if (endp[tr[j][s[i]]] == 0)
        dp[i][tr[j][s[i]]] = min(dp[i][tr[j][s[i]]], dp[i - 1][j]);
    }
  }
  int ans = 1e9;
  for (int j = 0; j <= tot; j++) {
    if (endp[j] == 0) ans = min(ans, dp[n][j]);
  }
  cout << ans;
}
