n=int(input())
i=1
s=0
for i in range(1,n+1):
    a=i//100
    b=i//10%10
    c=i%10
    if i%7==0 or a==7 or b==7 or c==7:
        continue
    if i%7!=0 and a!=7 and b!=7 and c!=7:
        s+=i
        i+=1
print(s)
/**************************************************************
	Problem: 1393
	User: admin
	Language: Python
	Result: Accepted
	Time:238 ms
	Memory:34480 kb
****************************************************************/