#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n;
for( int i = 1 ; i <= n ; i ++ )
if(i % 3 == 0)
{
int m = i;
while( m != 0 )
{
if ( m % 10 == 5 )
{
cout << i << endl;
break;
}
m = m / 10;
}
}
return 0;
}