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