#include <bits/stdc++.h>   using namespace std;   long long cont = 0;   template <typename T, typename F>   struct AHO_CORASICK {     const long long ALPHA = 26;     long long cv(F c) { return c -  0 ; }     vector<map<long long, long long>> tgo;     vector<long long> link;     vector<long long> ch;     vector<long long> p;     vector<bool> flag;     long long sz = 0;     long long size() { return sz; }     void new_node(long long tp, long long tch) {       sz++;       tgo.emplace_back();       link.push_back(0);       ch.push_back(tch);       p.push_back(tp);       flag.push_back(false);     }     AHO_CORASICK() {       new_node(0, 0);       new_node(1, 0);     }     void add_string(T cad) {       long long pt = 1;       for (long long i = 0; i < cad.size(); i++) {         long long tch = cv(cad[i]);         if (tgo[pt][tch] == 0) {           tgo[pt][tch] = sz;           new_node(pt, tch);         }         pt = tgo[pt][tch];       }       flag[pt] = true;     }     long long get_link(long long nodo) {       if (link[nodo] == 0) {         if (nodo == 1 || p[nodo] == 1)           link[nodo] = 1;         else           link[nodo] = go(get_link(p[nodo]), ch[nodo]);         flag[nodo] = flag[nodo] | flag[link[nodo]];       }       return link[nodo];     }     long long go(long long nodo, F tch) { return go(nodo, cv(tch)); }     long long go(long long nodo, long long tch) {       if (tgo[nodo][tch] == 0) {         tgo[nodo][tch] = (nodo == 1) ? 1 : go(get_link(nodo), tch);       }       return tgo[nodo][tch];     }   };   long long X;   vector<string> bf;   string temp;   void fff(long long sum) {     if (sum > X) return;     for (long long i = 0; i < temp.size(); i++) {       long long s = 0;       for (long long j = i; j < temp.size(); j++) {         s += temp[j] -  0 ;         if (s != X && X % s == 0) return;       }     }     if (sum == X) {       bf.push_back(temp);       return;     }     for (long long i = 1; i <= 9; i++) {       temp += (i +  0 );       fff(sum + i);       temp.pop_back();     }   }   const long long MAXN = 1010;   long long dp[MAXN][MAXN * 5];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (long long i = 0; i < MAXN; i++) {       for (long long j = 0; j < 5 * MAXN; j++) {         dp[i][j] = 1e9;       }     }     string cad;     cin >> cad;     cin >> X;     long long N = cad.size();     fff(0);     AHO_CORASICK<string, char> ac;     for (auto x : bf) {       ac.add_string(x);     }     dp[0][1] = 0;     for (long long i = 0; i < N; i++) {       for (long long j = 1; j < ac.size(); j++) {         long long pt = ac.go(j, cad[i]);         if (ac.flag[pt] == false) dp[i + 1][pt] = min(dp[i + 1][pt], dp[i][j]);         dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);       }     }     long long res = 1e9;     for (long long i = 0; i < ac.sz; i++) {       res = min(res, dp[N][i]);     }     cout << res <<   n ;     return 0;   }   