import sys
lines = sys.stdin.readline()
temp1_1 = int(lines.split(' ')[0])
temp2_1 = int(lines.split(' ')[1])
res1 = []
res2 =[]
temp1 = abs(temp1_1)#考虑到正负数的问题
if temp1:
while abs(temp1):
i = temp1 % 10
res1 += str(i)
temp1 //= 10
else:
res1=[0]
temp2 = abs(temp2_1)
if temp2:
while abs(temp2):
i = temp2 % 10
res2 += str(i)
temp2 //= 10
else:
res2 = [0]
result1 = 0
result2 = 0
for i in range(len(res1)):
result1 = result1 + int(res1[i]) * (7 ** i)
if temp1_1<0:
result1 = -result1
for i in range(len(res2)):
result2 = result2 + int(res2[i]) * (7 ** i)
if temp2_1<0:
result2 = -result2
res_num_temp = result1+result2
res3 = []
res_num = abs(res_num_temp)
if res_num ==0:
print(0)
else:
while abs(res_num):
i = res_num % 7
res3 +=str(i)
res_num //= 7
res3 = res3[::-1]
last_res = ''.join(res3)
if res_num_temp<0:
print(str(-int(last_res)))
else:
print(last_res)