#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
bool RELAXED = false;
template <int, typename T>
struct MINMAX {
  T val;
  MINMAX(T val) : val(val) {}
};
template <typename T>
MINMAX<1, T> MAX(T val) {
  return MINMAX<1, T>(val);
};
template <typename T>
MINMAX<2, T> MIN(T val) {
  return MINMAX<2, T>(val);
};
template <typename T, typename U>
inline T& operator|=(T& lhs, MINMAX<1, U> rhs) {
  return lhs = (rhs.val > lhs ? (RELAXED = true, rhs.val)
                              : (RELAXED = false, lhs));
}
template <typename T, typename U>
inline T& operator|=(T& lhs, MINMAX<2, U> rhs) {
  return lhs = (rhs.val < lhs ? (RELAXED = true, rhs.val)
                              : (RELAXED = false, lhs));
}
template <typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
inline vector<T> READ(int n) {
  vector<T> vec(n);
  for (int i = 0; i < int(n); i++) cin >> vec[i];
  return vec;
}
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T> >;
struct AhoCorasick {
  enum { alpha = 9, first = '1' };
  struct Node {
    int back, next[alpha], start = -1, end = -1, nmatches = 0;
    Node(int v) { memset(next, v, sizeof(next)); }
  };
  vector<Node> N;
  vector<int> backp;
  void insert(string& s, int j) {
    assert(!s.empty());
    int n = 0;
    for (char c : s) {
      int& m = N[n].next[c - first];
      if (m == -1) {
        n = m = int(N.size());
        N.emplace_back(-1);
      } else
        n = m;
    }
    if (N[n].end == -1) N[n].start = j;
    backp.push_back(N[n].end);
    N[n].end = j;
    N[n].nmatches++;
  }
  AhoCorasick(vector<string>& pat) : N(1, -1) {
    for (int i = 0; i < (int(pat.size())); ++i) insert(pat[i], i);
    N[0].back = int(N.size());
    N.emplace_back(0);
    queue<int> q;
    for (q.push(0); !q.empty(); q.pop()) {
      int n = q.front(), prev = N[n].back;
      for (int i = 0; i < (alpha); ++i) {
        int &ed = N[n].next[i], y = N[prev].next[i];
        if (ed == -1)
          ed = y;
        else {
          N[ed].back = y;
          (N[ed].end == -1 ? N[ed].end : backp[N[ed].start]) = N[y].end;
          N[ed].nmatches += N[y].nmatches;
          q.push(ed);
        }
      }
    }
  }
  int next(int& ptr, char c) {
    ptr = N[ptr].next[c - first];
    return N[ptr].end;
  }
};
vector<string> bad;
vector<int> cur;
void f(int x) {
  int sum = 0;
  for (int i = int(int(cur.size()) - 1); i >= int(0); --i) {
    sum += cur[i];
    if (sum != x && x % sum == 0) return;
  }
  if (sum == x) {
    string s;
    for (auto c : cur) s += (char)(c + '0');
    bad.push_back(s);
    return;
  }
  for (int i = int(1); i <= int(9); i++) {
    if (sum + i <= x) {
      cur.push_back(i);
      f(x);
      cur.pop_back();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(12);
  string s;
  int x;
  cin >> s >> x;
  int n = s.length();
  f(x);
  sort((bad).begin(), (bad).end());
  bad.resize(unique((bad).begin(), (bad).end()) - bad.begin());
  AhoCorasick ac(bad);
  int m = ac.N.size();
  const int INF = 1e9;
  vector<vector<int> > dp(1005, vector<int>(m, INF));
  dp[0][0] = 0;
  for (int i = 0; i < int(n); i++) {
    char c = s[i];
    for (int j = 0; j < int(m); j++) {
      if (dp[i][j] == INF) continue;
      int ptr = j;
      if (ac.next(ptr, c) < 0) {
        dp[i + 1][ptr] |= MIN(dp[i][j]);
      }
      dp[i + 1][j] |= MIN(dp[i][j] + 1);
    }
  }
  int ans = *min_element((dp[n]).begin(), (dp[n]).end());
  cout << ans << endl;
}
