#include <bits/stdc++.h>
#pragma GCC optimize(2)
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1010;
vector<int> vec;
char s[N];
int x;
struct trie {
  int ch[N * 10][15];
  int flag[N * 10];
  int fail[N * 10];
  int cnt = 0;
  void insert() {
    int len = vec.size();
    int root = 0;
    for (int i = 0; i < len; i++) {
      int c = vec[i];
      if (!ch[root][c]) ch[root][c] = ++cnt;
      root = ch[root][c];
    }
    flag[root] = 1;
  }
  void getfail() {
    int root = 0;
    fail[root] = -1;
    queue<int> q;
    for (int i = 0; i < 10; i++)
      if (ch[root][i]) q.push(ch[root][i]);
    while (!q.empty()) {
      int top = q.front();
      q.pop();
      for (int i = 0; i < 10; i++) {
        int v = ch[top][i];
        if (!v)
          ch[top][i] = ch[fail[top]][i];
        else {
          q.push(v);
          fail[v] = ch[fail[top]][i];
          flag[v] |= flag[fail[v]];
        }
      }
    }
  }
} T;
void dfs(int sum) {
  if (sum > x) return;
  if (sum == x) {
    for (int i = 0; i < vec.size(); i++) {
      int summ = 0;
      for (int j = i; j >= 0; j--) {
        summ += vec[j];
        if (summ != x) {
          if (x % summ == 0) return;
        }
      }
    }
    T.insert();
    return;
  }
  for (int i = 1; i <= 9; i++) {
    vec.push_back(i);
    dfs(sum + i);
    vec.pop_back();
  }
}
int dp[N][N * 10];
void test(int n) {
  cout << T.cnt << endl;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= T.cnt; ++j) {
      printf("%d ", dp[i][j]);
    }
    cout << endl;
  }
}
int main() {
  cin >> s;
  x = read();
  dfs(0);
  T.getfail();
  int n = strlen(s);
  memset(dp, INF, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= T.cnt; j++) {
      if (dp[i][j] >= INF) continue;
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
      int c = T.ch[j][s[i] - '0'];
      if (T.flag[c]) continue;
      dp[i + 1][c] = min(dp[i + 1][c], dp[i][j]);
    }
  }
  int ans = INF;
  for (int j = 0; j <= T.cnt; j++) ans = min(ans, dp[n][j]);
  cout << ans << endl;
  return 0;
}
