#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
struct Node {
  int c;
  int id;
  bool end;
  Node* child[10] = {NULL};
  Node* go[10] = {NULL};
  Node *suffixLink, *parent;
};
unordered_map<int, Node*> m;
Node* root = NULL;
Node* insert(Node* n, Node* p, string& s, int cur) {
  if (n == NULL) {
    n = new Node();
    n->c = n->end = 0;
    n->suffixLink = NULL;
    memset(n->child, NULL, 10);
    memset(n->go, NULL, 10);
    m[cnt] = n;
    n->id = cnt++;
    n->parent = p;
    if (cur >= 0) n->c = s[cur] - '0';
  }
  if (cur == s.size() - 1) {
    n->end = 1;
    return n;
  }
  int nxtChar = s[cur + 1] - '0';
  n->child[nxtChar] = insert(n->child[nxtChar], n, s, cur + 1);
  return n;
}
void generateXPrimes(string s, int x) {
  for (int i = 1; i <= 9; i++) {
    string t = s + (char)('0' + i);
    int su = 0, call = 1;
    for (int j = t.size() - 1; j > 0; j--) {
      su += t[j] - '0';
      if (x % su == 0) {
        call = 0;
        break;
      }
    }
    su += t[0] - '0';
    if (su == x && call) {
      root = insert(root, NULL, t, -1);
    } else if (call && su < x && x % su != 0) {
      generateXPrimes(t, x);
    }
  }
}
Node* go(Node* n, int c);
Node* suffixLink(Node* n) {
  if (n->parent == NULL) {
    return n;
  }
  if (n->parent->id == 0) {
    return n->parent;
  }
  if (n->suffixLink != NULL) {
    return n->suffixLink;
  }
  Node* pSuf = suffixLink(n->parent);
  return n->suffixLink = go(pSuf, n->c);
}
Node* go(Node* n, int c) {
  if (n->go[c] != NULL) {
    return n->go[c];
  }
  if (n->child[c] != NULL) {
    return n->go[c] = n->child[c];
  }
  if (n->parent == NULL) {
    return n;
  }
  Node* sufL = suffixLink(n);
  return n->go[c] = go(sufL, c);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  int t = 1;
  while (t--) {
    string s;
    int x;
    cin >> s >> x;
    generateXPrimes("", x);
    vector<int> res(cnt, INT_MAX);
    res[0] = 0;
    for (int i = 0; i < s.size(); i++) {
      vector<int> res2(res.size(), INT_MAX);
      for (int j = 0; j < res.size(); j++) {
        if (res[j] != INT_MAX) {
          res2[j] = min(res2[j], res[j] + 1);
          Node* n = m[j];
          Node* tr = go(n, s[i] - '0');
          if (tr != NULL && tr->end == 0) {
            res2[tr->id] = min(res2[tr->id], res[j]);
          }
        }
      }
      res = res2;
    }
    cout << *min_element(res.begin(), res.end());
  }
  return 0;
}
