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