#include <bits/stdc++.h>
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        std::chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
const int N = 1000;
const int K = 8;
int n, x;
std::unordered_map<int, int, custom_hash> st[N + 1];
char s[N + 1];
int dp(int len, int right) {
  if (!len) return 0;
  if (st[len].count(right)) return st[len][right];
  int d[K + 1], k, rr = right;
  d[0] = s[len - 1] - '0';
  for (k = 1; rr; ++k, rr /= 10) d[k] = rr % 10;
  int sum = 0;
  bool rm = false;
  for (int i = 0; i < k; ++i) {
    sum += d[i];
    if (sum == x) rm = true;
    if (!(x % sum) || sum > x) k = i;
  }
  int ans = dp(len - 1, right) + 1;
  if (!rm) {
    int next = 0;
    for (int i = k - 1; i >= 0; --i) {
      next *= 10;
      next += d[i];
    }
    ans = std::min(ans, dp(len - 1, next));
  }
  return st[len][right] = ans;
}
int main() {
  scanf("%s%d", s, &x);
  n = strlen(s);
  printf("%d\n", dp(n, 0));
  return 0;
}
