#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int n,i,num,res,a=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
num=i;
while(num)
{
res=num%10;
num/=10;
if(res==2||res==0||res==1||res==9)
{
a+=i;
break;
}
}
}
printf("%d",a);
return 0;
}