#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> mp;
int n;
int mi = INT_MAX;
void dfs(long long num){
string s = to_string(num);
if(s.size() >= n){
mi = min(mi, mp[num]);
return;
}
for(int i = 0; i < s.size(); i++){
if(mp[(s[i] - '0') * num] || s[i] - '0' == 1) continue;
mp[(s[i] - '0') * num] = mp[num] + 1;
dfs((s[i] - '0') * num);
}
}
signed main(){
long long x;
cin >> n >> x;
dfs(x);
if(mi == INT_MAX){
cout << -1;
}else cout << mi;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVub3JkZXJlZF9tYXA8aW50LCBpbnQ+IG1wOwppbnQgbjsKaW50IG1pID0gSU5UX01BWDsKdm9pZCBkZnMobG9uZyBsb25nIG51bSl7CglzdHJpbmcgcyA9IHRvX3N0cmluZyhudW0pOwoKCWlmKHMuc2l6ZSgpID49IG4pewoJCW1pID0gbWluKG1pLCBtcFtudW1dKTsKCQlyZXR1cm47Cgl9Cglmb3IoaW50IGkgPSAwOyBpIDwgcy5zaXplKCk7IGkrKyl7CgkJaWYobXBbKHNbaV0gLSAnMCcpICogbnVtXSB8fCBzW2ldIC0gJzAnID09IDEpIGNvbnRpbnVlOwoJCW1wWyhzW2ldIC0gJzAnKSAqIG51bV0gPSBtcFtudW1dICsgMTsgCgkJZGZzKChzW2ldIC0gJzAnKSAqIG51bSk7Cgl9CgkKfQpzaWduZWQgbWFpbigpewoJbG9uZyBsb25nIHg7CgljaW4gPj4gbiA+PiB4OwoJZGZzKHgpOwoJaWYobWkgPT0gSU5UX01BWCl7CgkJY291dCA8PCAtMTsKCX1lbHNlIGNvdXQgPDwgbWk7Cn0=