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