#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,r=1,s=0,a,d;
cin>>n;
while(r<=n){
a=r/10%10;
d=r/100;
if(r%10==7||a==7||d==7||r%7==0){
r++;
continue;
}
s=s+r;
r++;
}
cout<<s;
return 0;
}
/**************************************************************
Problem: 1393
User: zzz
Language: C++
Result: Accepted
Time:21 ms
Memory:2072 kb
****************************************************************/