#include <bits/stdc++.h>
using namespace std;
vector<string> PS;
void Solve(int x, vector<int>* digs) {
  if (std::accumulate(digs->begin(), digs->end(), 0) > x) return;
  for (int i = 0; i < digs->size(); i++) {
    int S = 0;
    for (int j = i; j < digs->size(); j++) {
      S += (*digs)[j];
      if (S < x && x % S == 0) {
        return;
      }
    }
  }
  if (std::accumulate(digs->begin(), digs->end(), 0) == x) {
    string S;
    for (int d : *digs) {
      S.push_back(d + '0');
    }
    PS.push_back(S);
    return;
  }
  for (int d = 1; d <= 9; d++) {
    digs->push_back(d);
    Solve(x, digs);
    digs->pop_back();
  }
}
vector<vector<int>> G;
long long dp[1111][5111];
int GetMin(int pos, int id, const vector<bool>& is_bad, const string& S) {
  int L = S.size();
  if (pos == L) return 0;
  if (dp[pos][id] != -1) return dp[pos][id];
  int ans = 1 + GetMin(pos + 1, id, is_bad, S);
  if (!is_bad[G[id][S[pos] - '0']]) {
    ans = min(ans, GetMin(pos + 1, G[id][S[pos] - '0'], is_bad, S));
  }
  return dp[pos][id] = ans;
}
int main() {
  string S;
  cin >> S;
  int x;
  cin >> x;
  vector<int> digs;
  Solve(x, &digs);
  set<string> uniq_pref_set;
  uniq_pref_set.insert("");
  for (int i = 0; i < PS.size(); i++) {
    for (int s = 1; s <= PS[i].size(); s++) {
      uniq_pref_set.insert(PS[i].substr(0, s));
    }
  }
  vector<string> uniq_pref(uniq_pref_set.begin(), uniq_pref_set.end());
  vector<bool> is_bad;
  for (const string& pref : uniq_pref) {
    bool curr_is_bad = false;
    for (const string& s : PS) {
      if (pref == s) {
        curr_is_bad = true;
      }
    }
    is_bad.push_back(curr_is_bad);
  }
  G.resize(uniq_pref.size());
  for (int i = 0; i < uniq_pref.size(); i++) {
    int L = uniq_pref[i].size();
  }
  vector<pair<int, int>> len_ids;
  for (int i = 0; i < uniq_pref.size(); i++) {
    len_ids.push_back({uniq_pref.size(), i});
  }
  sort(len_ids.begin(), len_ids.end(), greater<pair<int, int>>());
  for (int i = 0; i < uniq_pref.size(); i++) {
    G[i].resize(10);
    for (int d = 1; d <= 9; d++) {
      string newS = uniq_pref[i];
      newS.push_back(d + '0');
      int jnext = 0;
      int maxlen = 0;
      for (auto x : len_ids) {
        int j = x.second;
        if (x.first <= maxlen) break;
        if (newS.size() >= uniq_pref[j].size() &&
            maxlen < uniq_pref[j].size()) {
          int st = newS.size() - uniq_pref[j].size();
          bool is_match = true;
          for (int k = st; k < newS.size(); k++) {
            if (newS[k] != uniq_pref[j][k - st]) {
              is_match = false;
              break;
            }
          }
          if (is_match) {
            maxlen = uniq_pref[j].size();
            jnext = j;
          }
        }
      }
      G[i][d] = jnext;
    }
  }
  for (int i = 0; i <= S.size(); i++)
    for (int j = 0; j <= uniq_pref.size(); j++) dp[i][j] = -1;
  cout << GetMin(0, 0, is_bad, S) << endl;
}
