#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 1e9;
int trie[maxn][11];
int pc[maxn];
int pp[maxn];
bool term[maxn];
int cc = 1;
int sf[maxn];
int newn(int now, int d) {
  pc[cc] = d;
  pp[cc] = now;
  return cc++;
}
void add(string s) {
  int now = 0;
  for (char c : s) {
    int digit = c - '0';
    if (!trie[now][digit]) {
      trie[now][digit] = newn(now, digit);
    }
    now = trie[now][digit];
  }
  term[now] = true;
}
void build_aho() {
  queue<int> qq;
  qq.push(0);
  while (qq.size()) {
    int now = qq.front();
    qq.pop();
    for (int i = 1; i <= 9; i++) {
      if (trie[now][i]) {
        qq.push(trie[now][i]);
      }
    }
    if (now == 0) {
      sf[now] = -1;
      continue;
    } else if (pp[now] == 0) {
      sf[now] = 0;
    } else {
      sf[now] = trie[sf[pp[now]]][pc[now]];
    }
    for (int i = 1; i <= 9; i++) {
      if (!trie[now][i]) {
        trie[now][i] = trie[sf[now]][i];
      }
    }
  }
}
string s;
int x;
string buf;
void dfs(int sum) {
  if (sum > x) return;
  if (sum == x) {
    bool xprime = true;
    int len = buf.size();
    for (int i = 0; i < len && xprime; i++) {
      int cur = 0;
      for (int j = i; j < len && xprime; j++) {
        cur += int(buf[j] - '0');
        if (cur < x && x % cur == 0) {
          xprime = false;
        }
      }
    }
    if (xprime) {
      add(buf);
    }
    return;
  }
  for (int i = 1; i <= 9; i++) {
    buf += char('0' + i);
    dfs(sum + i);
    buf.pop_back();
  }
}
void relax(int &x, int y) { x = min(x, y); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  cin >> x;
  dfs(0);
  build_aho();
  int n = s.length();
  vector<vector<int>> dp(n + 1, vector<int>(cc + 10, inf));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < cc; j++) {
      if (dp[i][j] < inf) {
        relax(dp[i + 1][j], dp[i][j] + 1);
        int digit = int(s[i] - '0');
        int to = trie[j][digit];
        if (!term[to]) {
          relax(dp[i + 1][to], dp[i][j]);
        }
      }
    }
  }
  int ans = inf;
  for (int j = 0; j < cc; j++) {
    relax(ans, dp[n][j]);
  }
  cout << ans << endl;
  return 0;
}
