#include <bits/stdc++.h>
constexpr int MAXB = 1e5 ;
int sushi( int , int const B, std:: vector < int > const A) {
assert ( B <= MAXB) ;
if ( B == 0 ) return 0 ;
std:: bitset < MAXB + 1 > K( 1 ) ;
int R{ 1 } ;
for ( ;; ) {
auto K2 = K;
for ( auto const & a : A) K2 | = K2 << ( a * R) ;
if ( K2.test ( B) ) break ;
R * = 2 ;
K = K2;
if ( R > B) return - 1 ;
}
for ( int k{ R / 2 } ; k; k / = 2 ) {
auto K2 = K;
for ( auto const & a : A) K2 | = K2 << ( a * k) ;
if ( ! K2.test ( B) ) {
R | = k;
K = K2;
}
}
return R;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgpjb25zdGV4cHIgaW50IE1BWEIgPSAxZTU7CgppbnQgc3VzaGkoaW50LCBpbnQgY29uc3QgQiwgc3RkOjp2ZWN0b3I8aW50PiBjb25zdCBBKSB7Cglhc3NlcnQoQiA8PSBNQVhCKTsKCglpZiAoQiA9PSAwKSByZXR1cm4gMDsKCglzdGQ6OmJpdHNldDxNQVhCICsgMT4gSygxKTsKCWludCBSezF9OwoKCWZvciAoOzspIHsKCQlhdXRvIEsyID0gSzsKCQlmb3IgKGF1dG8gY29uc3QgJmEgOiBBKSBLMiB8PSBLMiA8PCAoYSAqIFIpOwoJCWlmIChLMi50ZXN0KEIpKSBicmVhazsKCQlSICo9IDI7CgkJSyA9IEsyOwoJCWlmIChSID4gQikgcmV0dXJuIC0xOwoJfQoKCWZvciAoaW50IGt7UiAvIDJ9OyBrOyBrIC89IDIpIHsKCQlhdXRvIEsyID0gSzsKCQlmb3IgKGF1dG8gY29uc3QgJmEgOiBBKSBLMiB8PSBLMiA8PCAoYSAqIGspOwoJCWlmICghSzIudGVzdChCKSkgewoJCQlSIHw9IGs7CgkJCUsgPSBLMjsKCQl9Cgl9CgoJcmV0dXJuIFI7Cn0=