
def call(n)
  i = 1;

  loop do
      x = i;
      if  x % 3 == 0
        STDOUT << " " << i;
        i += 1
        break unless i <= n
        next
      end
    
      loop do
        if  x % 10 == 3 
          STDOUT << " " << i;
          break;
        end
        x /= 10;
        break unless  x != 0
      end
      i += 1
    break unless i <= n
  end

  STDOUT << "\n"
end

#include <stdio.h>
n = gets.to_i
call(n)


