You are given an integer value x and a string s consisting of digits from 1 to 9 inclusive.

A substring of a string is a contiguous subsequence of that string.

Let f(l, r) be the sum of digits of a substring s[l..r].

Let's call substring s[l_1..r_1] x-prime if 

  * f(l_1, r_1) = x; 
  * there are no values l_2, r_2 such that 
    * l_1 ≤ l_2 ≤ r_2 ≤ r_1; 
    * f(l_2, r_2) ≠ x; 
    * x is divisible by f(l_2, r_2). 



You are allowed to erase some characters from the string. If you erase a character, the two resulting parts of the string are concatenated without changing their order.

What is the minimum number of characters you should erase from the string so that there are no x-prime substrings in it? If there are no x-prime substrings in the given string s, then print 0.

Input

The first line contains a string s (1 ≤ |s| ≤ 1000). s contains only digits from 1 to 9 inclusive.

The second line contains an integer x (1 ≤ x ≤ 20).

Output

Print a single integer — the minimum number of characters you should erase from the string so that there are no x-prime substrings in it. If there are no x-prime substrings in the given string s, then print 0.

Examples

Input


116285317
8


Output


2


Input


314159265359
1


Output


2


Input


13
13


Output


0


Input


3434343434
7


Output


5

Note

In the first example there are two 8-prime substrings "8" and "53". You can erase these characters to get rid of both: "116285317". The resulting string "1162317" contains no 8-prime substrings. Removing these characters is also a valid answer: "116285317".

In the second example you just have to erase both ones.

In the third example there are no 13-prime substrings. There are no substrings with the sum of digits equal to 13 at all.

In the fourth example you can have neither "34", nor "43" in a string. Thus, you have to erase either all threes or all fours. There are 5 of each of them, so it doesn't matter which.
#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class S, class T>
std::ostream& operator<<(std::ostream& out, const std::pair<S, T>& a) {
  std::cout << '(' << a.first << ", " << a.second << ')';
  return out;
}
template <class T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
  std::cout << '[';
  for (ll i = (0); i < (a.size()); ++i) {
    std::cout << a[i];
    if (i != a.size() - 1) std::cout << ", ";
  }
  std::cout << ']';
  return out;
}
struct Node {
  ll nxt[10];
  ll p;
  char pch;
  ll link;
  ll go[10];
  bool term;
  Node() {
    memset(nxt, -1, sizeof(nxt));
    memset(go, -1, sizeof(go));
    link = p = -1;
    term = false;
  }
  ll& operator[](ll x) { return nxt[x]; }
};
std::vector<Node> trie;
void add_string(const std::string& s) {
  ll v = 0;
  for (auto ch : s) {
    ll c = ch - '1';
    if (trie[v][c] == -1) {
      trie.emplace_back(Node());
      trie[trie.size() - 1].p = v;
      trie[trie.size() - 1].pch = c;
      trie[v][c] = trie.size() - 1;
    }
    v = trie[v][c];
  }
  trie[v].term = true;
  return;
}
ll go(ll v, ll c);
ll get_link(ll v) {
  if (trie[v].link == -1) {
    if (v == 0 || trie[v].p == 0)
      trie[v].link = 0;
    else
      trie[v].link = go(get_link(trie[v].p), trie[v].pch);
  }
  return trie[v].link;
}
ll go(ll v, ll c) {
  if (trie[v].go[c] == -1) {
    if (trie[v][c] != -1)
      trie[v].go[c] = trie[v][c];
    else
      trie[v].go[c] = (!v ? 0 : go(get_link(v), c));
  }
  return trie[v].go[c];
}
std::string s;
ll x;
std::string t;
void generate(ll i, ll sum) {
  if (sum == x) {
    bool fl = true;
    for (ll l = (0); l < (t.size()); ++l) {
      ll cur = 0;
      for (ll r = (l); r < (t.size()); ++r) {
        cur += t[r] - '0';
        if (x % cur == 0 && cur != x) fl = false;
      }
    }
    if (fl) {
      add_string(t);
    }
    return;
  }
  for (ll j = (1); j < (std::min(x - sum, 9ll) + 1); ++j) {
    t += '0' + j;
    generate(i + 1, sum + j);
    t.pop_back();
  }
}
int main() {
  std::cin >> s >> x;
  trie.emplace_back(Node());
  generate(0, 0);
  std::vector<std::vector<ll>> dp(s.size() + 1,
                                  std::vector<ll>(trie.size(), INF));
  dp[0][0] = 0;
  for (ll i = (0); i < (s.size()); ++i)
    for (ll j = (0); j < (trie.size()); ++j)
      if (dp[i][j] != INF) {
        chmin(dp[i + 1][j], dp[i][j] + 1);
        ll nxt = go(j, s[i] - '1');
        if (!trie[nxt].term) chmin(dp[i + 1][nxt], dp[i][j]);
      }
  std::cout << *min_element((dp[s.size()]).begin(), (dp[s.size()]).end())
            << '\n';
  return 0;
}
