#include<bits/stdc++.h>
using namespace std;
//函数判断数字有没有位数是5
bool havefive(int n){
while(n){
if(n%10==5) return true;
else n/=10;
}
return false;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
if(i%3==0&&havefive(i)) cout<<i<<endl;
}
}