#include<iostream>
using namespace std;
using ll = long long;
ll n,sum;
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
int k = i;
do {
if (k % 10 == 2 || k % 10 == 0 || k % 10 == 1 || k % 10 == 9)
{
sum += i;
break;
}
} while (k /= 10);
}
cout << sum;
return 0;
}