print('', ' '.join([str(x) for x in range(1, int(input()) + 1) if x % 3 == 
    0 or '3' in str(x)]))

fa4d2f423db31ddacd62456d22855f93cc8f3e74
<mask token>

print('', ' '.join([str(x) for x in range(1, int(input()) + 1) if x % 3 == 
    0 or '3' in str(x)]))
