#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, INF = 0x3f3f3f3f;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
inline int getsum(string s) {
  int ret = 0;
  for (char c : s) {
    ret += c - '0';
  }
  return ret;
}
inline bool check(string &s, int x) {
  for (int i = 0; i < s.length(); ++i) {
    for (int j = i; j < s.length(); ++j) {
      int sum = getsum(s.substr(i, j - i + 1));
      if (sum > x || (j - i + 1 < s.length() && x % sum == 0)) {
        return 0;
      }
    }
  }
  return 1;
}
vector<string> gen(int x) {
  vector<int> num;
  vector<string> ret;
  queue<string> q;
  for (int i = 1; i <= min(x, 9); ++i) {
    if (i == x || x % i != 0) {
      num.push_back(i);
    }
  }
  for (int v : num) {
    q.push(to_string(v));
  }
  while (!q.empty()) {
    string cur = q.front();
    q.pop();
    int sum = getsum(cur);
    if (sum == x) {
      ret.push_back(cur);
    } else {
      for (int v : num) {
        string nx = cur + char('0' + v);
        if (check(nx, x)) {
          q.push(nx);
        }
      }
    }
  }
  return ret;
}
struct AC_auto {
  int ch[N][10];
  int num[N], fail[N];
  int tot;
  void init() {
    tot = 0;
    for (int i = 0; i < 10; ++i) ch[0][i] = 0;
  }
  void insert(string &s) {
    int u = 0, len = s.length();
    for (int i = 0; i < len; i++) {
      if (!ch[u][s[i] - '0']) {
        ch[u][s[i] - '0'] = ++tot;
        for (int j = 0; j < 10; ++j) ch[tot][j] = 0;
        num[tot] = fail[tot] = 0;
      }
      u = ch[u][s[i] - '0'];
    }
    num[u]++;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 10; i++) {
      if (ch[0][i]) fail[ch[0][i]] = 0, q.push(ch[0][i]);
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 10; i++)
        if (ch[u][i]) {
          fail[ch[u][i]] = ch[fail[u]][i];
          q.push(ch[u][i]);
        } else
          ch[u][i] = ch[fail[u]][i];
    }
  }
} AC;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  int x;
  cin >> s >> x;
  vector<string> v = gen(x);
  AC.init();
  for (auto &str : v) {
    AC.insert(str);
  }
  AC.build();
  int sz = AC.tot;
  vector<int> dp(sz + 1, INF);
  dp[0] = 0;
  for (char c : s) {
    vector<int> nxdp(sz + 1, INF);
    for (int i = 0; i <= sz; ++i) {
      nxdp[i] = dp[i] + 1;
    }
    for (int i = 0; i <= sz; ++i) {
      int nx = AC.ch[i][c - '0'];
      if (AC.num[nx]) {
        continue;
      }
      nxdp[nx] = min(nxdp[nx], dp[i]);
    }
    swap(dp, nxdp);
  }
  cout << *min_element(dp.begin(), dp.end()) << endl;
}
