#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using ll = long long;
const int MAXN = 1001;
int N, X;
string str;
unordered_map<ll, int> memo;
inline ll genHash(int i, string state) {
  return (state.length() == 0 ? 0 : stoll(state)) * 2937 + i;
}
int doDP(int i, string state) {
  ll hashed = genHash(i, state);
  auto ptr = memo.find(hashed);
  if (ptr != memo.end()) {
    return ptr->second;
  }
  if (i == N) return 0;
  int dpVal = 1 + doDP(i + 1, state);
  string newState = state + str[i];
  int currS = 0;
  for (int j = newState.length() - 1; j >= 0; j--) {
    currS += newState[j] - '0';
    if (currS == X) {
      break;
    } else if (currS > X) {
      newState = newState.substr(j + 1);
      break;
    } else if (X % currS == 0) {
      newState = newState.substr(j + 1);
      break;
    }
  }
  if (currS != X) {
    dpVal = min(doDP(i + 1, newState), dpVal);
  }
  memo[hashed] = dpVal;
  return dpVal;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> str >> X;
  N = str.length();
  doDP(0, "");
  ll hashed = genHash(0, "");
  cout << memo[hashed] << '\n';
  return 0;
}
