百练 / 2019计算机学科夏令营上机考试 D:上楼梯
DP
# 百练 / 2019计算机学科夏令营上机考试 D:上楼梯
# http://bailian.openjudge.cn/xly2019/D/
# Author:NitrogenousFish
# github:https://github.com/NITROGENousFish/
def main():
num_list = []
while(1):
input_thing = list(map(int,input().split()))
if input_thing[0] == 0 and input_thing[1] == 0:
break
else:
num_list.append(input_thing)
for number_list in num_list:
stair = number_list[0]
step_list = [i for i in range(1,number_list[1]+1) if str(i).find("4")==-1]
output = [0]*(stair+1)
# print(step_list)
for counter in range(1,stair+1):
for step in step_list:
if step<counter:
output[counter] += output[counter-step]
if step==counter:
output[counter]+=1
print(output[-1])
if __name__ == "__main__":
main()