#include<bits/stdc++.h>
using namespace std;
int n,g,s,b,h;
int main(){
cin>>n;
while(n>=1){
g=n%10;
s=n/10%10;
b=n/100;
if(g!=7&&n%7!=0&&s!=7&&b!=7) h+=n;
n--;
}
cout<<h;
return 0;
}
/**************************************************************
Problem: 1393
User: zhangziang
Language: C++
Result: Accepted
Time:17 ms
Memory:2072 kb
****************************************************************/