n = gets.to_i

s = []
i = 1

while (i <= n)
    x = i
    if ( x % 3 == 0 )
        s.push(i)
        i += 1
        next
    else
        while (x != 0)
            if ( x % 10 == 3)
                s.push(i)
                break
            else
                x = x/10;
            end
        end
    end
	i += 1
end

puts ' ' + s.join(' ')
