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} 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: 100000} ans=[0 for i in range(0,100001)] 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()) q=[N] count=0 while q: x=heapq.heappop(q) p=x//3 r=x//5 if 100000>=p: count+=ans[p] else: heapq.heappush(q,p) if 100000>=r: count+=ans[r] else: heapq.heappush(q,r) print(count)