import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
{
Scanner in
= new Scanner
(System.
in); long n, m, t, sum;
n = in.nextLong();
m = in.nextLong();
for(long i = 1; i < n; i++) {
t = i;
sum = 0;
while(t != 0
sum += t%10;
t /= 10;
}
if(sum
*sum
== m
) System.
out.
print(i
+ " "); }
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBNYWluCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCVNjYW5uZXIgaW4gPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwogICAgCWxvbmcgbiwgbSwgdCwgc3VtOwogICAgCW4gPSBpbi5uZXh0TG9uZygpOyAKICAgIAltID0gaW4ubmV4dExvbmcoKTsKICAgIAlmb3IobG9uZyBpID0gMTsgaSA8IG47IGkrKykgewogICAgICAgIAl0ID0gaTsKICAgICAgICAJc3VtID0gMDsKCSAgICAgICAgd2hpbGUodCAhPSAwCgkgICAgICAgICAgICBzdW0gKz0gdCUxMDsKCSAgICAgICAgICAgIHQgLz0gMTA7CgkgICAgICAgIH0KICAgICAgICBpZihzdW0qc3VtID09IG0pIFN5c3RlbS5vdXQucHJpbnQoaSArICIgIik7CiAgICAJfQogICAgfQp9