#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(
    (unsigned)chrono::system_clock::now().time_since_epoch().count());
const long double PI = acosl(-1);
const int nmax = 2400 * 11;
const int alpha = 10;
int tsz;
int nxt[nmax + 1][alpha];
int parent[nmax + 1], EndCnt[nmax + 1], WordCnt[nmax + 1];
int MakeNode(int par) {
  if (par == -1) tsz = 0;
  parent[tsz] = par, EndCnt[tsz] = 0, WordCnt[tsz] = 0;
  memset(nxt[tsz], -1, sizeof(nxt[tsz]));
  return tsz++;
}
int TrieInsert(char* str) {
  int cur = 0;
  WordCnt[cur]++;
  for (int i = 0; str[i] != 0; i++) {
    if (nxt[cur][str[i] - '0'] == -1) nxt[cur][str[i] - '0'] = MakeNode(cur);
    cur = nxt[cur][str[i] - '0'];
    WordCnt[cur]++;
  }
  EndCnt[cur]++;
  return cur;
}
char bad[100];
int pref[25];
vector<string> bads;
void backtrack(int pos, int cur, int sum) {
  if (cur == sum) {
    bad[pos] = 0;
    TrieInsert(bad);
    return;
  }
  for (int d = 1; d <= 9 && d + cur <= sum; d++) {
    pref[pos] = (pos == 0) ? d : pref[pos - 1] + d;
    if (sum != pref[pos] && sum % pref[pos] == 0) continue;
    bool ok = true;
    for (int i = 0; i < pos; i++)
      if (sum % (pref[pos] - pref[i]) == 0) {
        ok = false;
        break;
      }
    if (!ok) continue;
    bad[pos] = '0' + d;
    backtrack(pos + 1, cur + d, sum);
  }
}
int Failure[nmax + 1];
int transition[nmax + 1][alpha];
void AhoCorasickBuild() {
  queue<int> q;
  Failure[0] = -1;
  for (int i = 0; i < alpha; i++) {
    if (nxt[0][i] == -1) continue;
    transition[0][i] = nxt[0][i];
    Failure[nxt[0][i]] = 0;
    q.push(nxt[0][i]);
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    EndCnt[v] += EndCnt[Failure[v]];
    for (int i = 0; i < alpha; i++) {
      if (nxt[v][i] == -1) {
        transition[v][i] = transition[Failure[v]][i];
        continue;
      }
      transition[v][i] = nxt[v][i];
      int n = nxt[v][i];
      int cur = Failure[v];
      while (cur != 0 && nxt[cur][i] == -1) cur = Failure[cur];
      if (nxt[cur][i] != -1) cur = nxt[cur][i];
      Failure[n] = cur;
      q.push(n);
    }
  }
  return;
}
const int smax = 2e3 + 10;
char input[smax];
int dp[2][nmax + 1];
int main() {
  MakeNode(-1);
  cin >> input;
  int n = strlen(input);
  int k;
  cin >> k;
  backtrack(0, 0, k);
  AhoCorasickBuild();
  int cur = 0;
  for (int i = 0; i < tsz; i++) {
    if (EndCnt[i] > 0)
      dp[cur][i] = 2 * n;
    else
      dp[cur][i] = 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    cur = cur ^ 1;
    for (int j = 0; j < tsz; j++) {
      if (EndCnt[j] > 0) {
        dp[cur][j] = 2 * n;
        continue;
      }
      dp[cur][j] = dp[cur ^ 1][j] + 1;
      dp[cur][j] = min(dp[cur][j], dp[cur ^ 1][transition[j][input[i] - '0']]);
    }
  }
  cout << dp[cur][0] << endl;
}
