#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2, M = 5e5 + 2;
char s[N];
struct Aho {
  int ch[M][10], fail[M], fg[M], q[M];
  int tot;
  void init() {
    tot = 0;
    memset(ch[0], 0, sizeof ch[0]);
  }
  int newnode() {
    memset(ch[++tot], 0, sizeof ch[tot]);
    fail[tot] = fg[tot] = 0;
    return tot;
  }
  void insert(string s) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      if (!ch[now][s[i] - '0']) ch[now][s[i] - '0'] = newnode();
      now = ch[now][s[i] - '0'];
    }
    fg[now]++;
  }
  void build() {
    int hd = 0, tl = 0;
    for (int i = 0; i < 10; i++)
      if (ch[0][i]) q[++tl] = ch[0][i];
    while (hd < tl) {
      int u = q[++hd];
      fg[u] |= fg[fail[u]];
      for (int i = 0; i < 10; i++)
        if (ch[u][i]) {
          q[++tl] = ch[u][i];
          fail[ch[u][i]] = ch[fail[u]][i];
        } else
          ch[u][i] = ch[fail[u]][i];
    }
  }
  int dp[1002][10001];
  void solve() {
    memset(dp, 0x3f, sizeof dp);
    int n = strlen(s + 1);
    dp[0][0] = 0;
    for (int j = 0; j <= tot; j++) {
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= tot; j++) {
        if (fg[j]) continue;
        int k = s[i + 1] - '0';
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
        if (!fg[ch[j][k]])
          dp[i + 1][ch[j][k]] = min(dp[i + 1][ch[j][k]], dp[i][j]);
      }
    }
    int ans = 1e9;
    for (int i = 0; i <= tot; i++) ans = min(ans, dp[n][i]);
    printf("%d\n", ans);
  }
} aho;
bool ok(string s, int m) {
  for (int i = 1; i < m; i++)
    if (m % i == 0) {
      for (int j = 0; j < s.size(); j++) {
        for (int k = j; k < s.size(); k++) {
          int sum = 0;
          for (int h = j; h <= k; h++) sum += s[h] - '0';
          if (sum == i) return 0;
        }
      }
    }
  return 1;
}
void gao(string t, int now, int m) {
  if (now > m) return;
  if (now == m && ok(t, m)) aho.insert(t);
  for (int i = 1; i <= 9; i++) gao(t + to_string(i), now + i, m);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, t;
  cin >> s + 1;
  cin >> m;
  aho.init();
  gao("", 0, m);
  aho.build();
  aho.solve();
  return 0;
}
