#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
const int N=1e5+9,p=1e9+7;
ll ans,n,m,k,q;
string s;
void dfs(int len,ll l,ll sum,ll j){
if(len>=s.size()-1){
if(sum+l*10+s[len]-'0'==n) ans=min(ans,j);
return;
}
dfs(len+1,0,sum+l*10+s[len]-'0',j+1);
dfs(len+1,l*10+s[len]-'0',sum,j);
}
void solve(){
cin>>s>>n;
ans=1e9;
dfs(0,0,0,0);
if(ans<10000) cout<<ans;
else cout<<-1;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
while(T--){
solve();
cout<<"\n";
}
return 0;
}