#include<iostream>
using namespace std;
bool check(int n){
while(n>0){
int y=n%10;
if(y==0||y==1||y==2||y==9){
return true;
}else{
n/=10;
}
}
return false;
}
int main(){
int n;
cin>>n;
int res=0;
for(int i=1;i<=n;i++){
if(check(i)){
res+=i;
}
}
cout<<res<<endl;
return 0;
}