#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int x;
int nd;
const int sz = 10;
int cnt[MAXN];
int ch[MAXN][sz];
int ne[MAXN];
void init() {
  nd = 0;
  memset(cnt, 0, sizeof(cnt));
  memset(ch, 0, sizeof(ch));
  memset(ne, 0, sizeof(ne));
}
string w(22, '0');
void insert(int n) {
  int p = 0;
  for (int i = 1; i <= n; i++) {
    int t = w[i] - '0';
    if (!ch[p][t]) {
      ch[p][t] = ++nd;
    }
    p = ch[p][t];
  }
  cnt[p] = 1;
}
void build() {
  queue<int> que;
  for (int i = 0; i < sz; i++) {
    if (ch[0][i]) {
      que.push(ch[0][i]);
    }
  }
  while (!que.empty()) {
    int t = que.front();
    que.pop();
    for (int i = 0; i < sz; i++) {
      int p = ch[t][i];
      if (!p) {
        ch[t][i] = ch[ne[t]][i];
      } else {
        ne[p] = ch[ne[t]][i];
        que.push(p);
        cnt[p] |= cnt[ne[p]];
      }
    }
  }
}
bool check(int n) {
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    for (int j = i; j <= n; j++) {
      sum += w[j] - '0';
      if (sum != x && x % sum == 0) {
        return false;
      }
    }
  }
  return true;
}
void dfs(int u, int rest) {
  if (!rest) {
    if (check(u - 1)) {
      insert(u - 1);
    }
    return;
  }
  for (int i = 1; i <= 9; i++) {
    if (rest - i >= 0) {
      w[u] = '0' + i;
      dfs(u + 1, rest - i);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  string s;
  cin >> s;
  s = "1" + s;
  cin >> x;
  dfs(1, x);
  build();
  vector<int> dp[2];
  for (int i = 0; i <= nd; i++) {
    dp[0].push_back(INF);
    dp[1].push_back(INF);
  }
  dp[0][0] = 0;
  for (int i = 0; i < s.length() - 1; i++) {
    for (int j = 0; j <= nd; j++) {
      dp[(i + 1) & 1][j] = min(INF, dp[i & 1][j] + 1);
    }
    for (int j = 0; j <= nd; j++) {
      for (int k = 1; k <= 9; k++) {
        if (s[i + 1] == '0' + k) {
          int p = ch[j][k];
          if (!cnt[p]) {
            dp[(i + 1) & 1][p] = min(dp[(i + 1) & 1][p], dp[i & 1][j]);
          }
        }
      }
    }
  }
  int ans = INF;
  for (auto v : dp[(s.length() - 1) & 1]) {
    ans = min(ans, v);
  }
  cout << ans;
  return 0;
}
