#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
  putchar(' ');
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
using namespace std;
struct Node {
  int child[9];
  int par;
  int c;
  int back[9];
  int suffixLink;
  bool leaf;
  Node() {
    for (int i = (0); i <= (8); ++i) {
      child[i] = back[i] = -1;
    }
    par = c = suffixLink = -1;
    leaf = false;
  }
};
vector<Node *> trie;
vector<int> a, cur;
Node *p;
int x, dp[1005][5005];
vector<vector<int> > save;
void prepare(int remain) {
  if (remain == 0) {
    int sz = cur.size();
    for (int len = (1); len <= (sz - 1); ++len) {
      int sum = 0;
      for (int l = (0); l <= (len - 2); ++l) {
        sum += cur[l];
      }
      for (int l = (len - 1); l <= (sz - 1); ++l) {
        sum += cur[l];
        if (x % sum == 0) {
          return;
        }
        sum -= cur[l - len + 1];
      }
    }
    for (int &v : cur) {
      --v;
    }
    save.push_back(cur);
    for (int &v : cur) {
      ++v;
    }
    return;
  }
  for (int i = (1); i <= (min(remain, 9)); ++i) {
    cur.push_back(i);
    prepare(remain - i);
    cur.pop_back();
  }
}
int go(int cur, int c);
int getLink(int cur) {
  Node *temp = trie[cur];
  if (temp->suffixLink == -1) {
    if (cur == 0 || temp->par == 0) {
      temp->suffixLink = 0;
    } else {
      temp->suffixLink = go(getLink(temp->par), temp->c);
    }
  }
  return temp->suffixLink;
}
int go(int cur, int c) {
  Node *temp = trie[cur];
  if (temp->back[c] == -1) {
    if (temp->child[c] != -1) {
      temp->back[c] = temp->child[c];
    } else {
      temp->back[c] = (cur == 0 ? 0 : go(getLink(cur), c));
    }
  }
  return temp->back[c];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie();
  if (fopen(".inp", "r")) freopen(".inp", "r", stdin);
  string s;
  cin >> s >> x;
  for (char c : s) {
    a.push_back(c - '0' - 1);
  }
  prepare(x);
  p = new Node();
  trie.push_back(p);
  for (auto v : save) {
    int t = 0;
    for (auto u : v) {
      p = trie[t];
      if (p->child[u] == -1) {
        Node *q = new Node();
        p->child[u] = trie.size();
        trie.push_back(q);
        q->c = u;
        q->par = t;
      }
      t = p->child[u];
    }
    p = trie[t];
    p->leaf = true;
  }
  int asz = a.size();
  int trsz = trie.size();
  for (int i = (0); i <= (asz); ++i) {
    for (int j = (0); j <= (trsz); ++j) {
      dp[i][j] = 1000000007;
    }
  }
  dp[0][0] = 0;
  for (int i = (0); i <= (asz - 1); ++i) {
    for (int j = (0); j <= (trsz - 1); ++j) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
      int nx = go(j, a[i]);
      if (trie[nx]->leaf == false) {
        dp[i + 1][nx] = min(dp[i + 1][nx], dp[i][j]);
      }
    }
  }
  int ans = 1000000007;
  for (int i = (0); i <= (trsz - 1); ++i) {
    ans = min(ans, dp[asz][i]);
  }
  cout << ans;
  return 0;
}
