include<stdio.h>
int n,x,t;
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;i ++){
t = i;
if(i%3 == 0)
while(t != 0){
if(t%10 == 5){
printf("%d\n",i);
break;
}
t /= 10;
}
}
}