#include<bits/stdc++.h>
using namespace std;
bool judge(int i)
{
while(i)
{
int t = i % 10;
if((t == 2) || (t == 0) || (t == 1) || (t == 9)) return true;
i /= 10;
}
return false;
}
int main()
{
int ans = 0;
int n;cin >> n;
for (int i = 1; i <= n; i++)
{
if(judge(i)) ans += i;
}
cout << ans << '\n';
return 0;
}