#include <iostream>
using namespace std;
int main() {
int n, c;
cin >> n >> c;
const int ten = 10;
int nouNumar = 0;
int number = 0;
int repetari = 0;
while (n > 0) {//here we find what is the new number but in mirror
number = n % ten;
if (number != c) {
nouNumar = (nouNumar + number) * ten;
if (n < ten) {
nouNumar /= ten;
}
}
number = 0;
n /= ten;
}
//we reverse the mirror
int mirror = 0, i = 0;
while (nouNumar > 0) {
i = nouNumar % ten;
mirror = (mirror + i) * ten;
if (nouNumar < ten) {
mirror /= ten;
}
nouNumar /= ten;
}
if (mirror == 0) {
mirror = -1;
}
cout << mirror;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbiwgYzsKCWNpbiA+PiBuID4+IGM7Cgljb25zdCBpbnQgdGVuID0gMTA7CglpbnQgbm91TnVtYXIgPSAwOwoJaW50IG51bWJlciA9IDA7CglpbnQgcmVwZXRhcmkgPSAwOwoJd2hpbGUgKG4gPiAwKSB7Ly9oZXJlIHdlIGZpbmQgd2hhdCBpcyB0aGUgbmV3IG51bWJlciBidXQgaW4gbWlycm9yCgkJbnVtYmVyID0gbiAlIHRlbjsKCQlpZiAobnVtYmVyICE9IGMpIHsKCQkJbm91TnVtYXIgPSAobm91TnVtYXIgKyBudW1iZXIpICogdGVuOwoJCQlpZiAobiA8IHRlbikgewoJCQkJbm91TnVtYXIgLz0gdGVuOwoJCQl9CgkJfQoJCW51bWJlciA9IDA7CgkJbiAvPSB0ZW47Cgl9CgkvL3dlIHJldmVyc2UgdGhlIG1pcnJvcgoJaW50IG1pcnJvciA9IDAsIGkgPSAwOwoJd2hpbGUgKG5vdU51bWFyID4gMCkgewoJCWkgPSBub3VOdW1hciAlIHRlbjsKCQltaXJyb3IgPSAobWlycm9yICsgaSkgKiB0ZW47CgkJaWYgKG5vdU51bWFyIDwgdGVuKSB7CgkJCW1pcnJvciAvPSB0ZW47CgkJfSAKCQlub3VOdW1hciAvPSB0ZW47Cgl9CglpZiAobWlycm9yID09IDApIHsKCQltaXJyb3IgPSAtMTsKCX0KCWNvdXQgPDwgbWlycm9yOwoJcmV0dXJuIDA7Cn0=