from collections import defaultdict import heapq ansmin= {2: 1, 3: 3, 4: 5, 5: 9, 7: 15, 8: 25, 9: 27, 12: 45, 15: 75, 16: 81, 17: 125, 21: 135, 27: 225, 28: 243, 32: 375, 37: 405, 38: 625, 48: 675, 49: 729, 59: 1125, 65: 1215, 70: 1875, 85: 2025, 86: 2187, 87: 3125, 107: 3375, 114: 3645, 129: 5625, 150: 6075, 151: 6561, 157: 9375, 192: 10125, 200: 10935, 201: 15625, 236: 16875, 264: 18225, 265: 19683, 286: 28125, 342: 30375, 351: 32805, 358: 46875, 428: 50625, 464: 54675, 465: 59049, 466: 78125, 522: 84375, 606: 91125, 616: 98415, 644: 140625, 770: 151875, 815: 164025, 816: 177147, 824: 234375, 950: 253125, 1070: 273375, 1081: 295245, 1082: 390625, 1166: 421875, 1376: 455625, 1431: 492075, 1432: 531441, 1468: 703125, 1720: 759375, 1885: 820125, 1897: 885735} ansmax= {2: 2, 3: 4, 4: 8, 5: 14, 7: 24, 8: 26, 9: 44, 12: 74, 15: 80, 16: 124, 17: 134, 21: 224, 27: 242, 28: 374, 32: 404, 37: 624, 38: 674, 48: 728, 49: 1124, 59: 1214, 65: 1874, 70: 2024, 85: 2186, 86: 3124, 87: 3374, 107: 3644, 114: 5624, 129: 6074, 150: 6560, 151: 9374, 157: 10124, 192: 10934, 200: 15624, 201: 16874, 236: 18224, 264: 19682, 265: 28124, 286: 30374, 342: 32804, 351: 46874, 358: 50624, 428: 54674, 464: 59048, 465: 78124, 466: 84374, 522: 91124, 606: 98414, 616: 140624, 644: 151874, 770: 164024, 815: 177146, 816: 234374, 824: 253124, 950: 273374, 1070: 295244, 1081: 390624, 1082: 421874, 1166: 455624, 1376: 492074, 1431: 531440, 1432: 703124, 1468: 759374, 1720: 820124, 1885: 885734, 1897: 1000000} ans=[0 for i in range(0,1000001)] for key in ansmin.keys(): a=ansmin[key] b=ansmax[key] for j in range(a,b+1): ans[j]=key ans[0]=1 N=int(input()) if N==0: print(1) else: q=[N] count=0 while q: x=heapq.heappop(q) p=x//3 r=x//5 if 1000000>=p: count+=ans[p] else: heapq.heappush(q,p) if 1000000>=r: count+=ans[r] else: heapq.heappush(q,r) print(count)