n=int(input())
m=int(input())
for i in range (1,n+1):
number=i
sum=0
while number>0:
sum=sum+number%10
number=number//10
if sum**2==m:
print(i)
n=int(input())
m=int(input())
for i in range (1,n+1):
number=i
sum=0
while number>0:
sum=sum+number%10
number=number//10
if sum**2==m:
print(i)