def check_num
  @x = @i
  if ( @x % 3 == 0 ) then
    print " " + @i.to_s
    @i += 1
    if @i <= @n then
      check_num
    else
      puts ""
    end
  else
    include_3()
  end
end

def include_3
  if @x % 10 == 3 then
    print " " + @i.to_s
    @i += 1
    if @i <= @n then
      check_num
    else
      puts ""
    end
  else
    @x /= 10
    if @x != 0 then
      include_3 
    else 
      @i += 1
      if @i <= @n then
        check_num
      else
        puts ""
      end
    end
  end
end

@n = gets.chomp.to_i
@i = 1
check_num()