n, m = map(int, input().split()) list1=[]for i in range(1000 ,m + 1): a = int(str(i)[0]) b = int(str(i)[1]) c = int(str(i)[2]) d = int(str(i)[3]) if a**4+b**4+c**4+d**4==i: list1.append(i) print(len(list1),*list1)