#include <iostream>
#include <unordered_set>
using namespace std;

struct List {
	int data = 0;
	List* next = nullptr;
	List(int x) : data(x) {}
};

void remove_duplicates(List* head) {
	std::unordered_set<int> cache;
	cache.insert(head->data);
	List* next = head->next;
	while (next != nullptr) {
		if (cache.count(next->data) > 0) {
			head->next = next->next;
			delete next;
			next = head->next;
		} else {
			cache.insert(next->data);
			head = next;
			next = head->next;
		}
	}
}

int main() {
	List* head = new List(1);
	List* list = head;
	for (int index = 2; index < 10; ++index) {
		List* next = new List(index);
		if (next->data % 2 == 0) {
			next->data = 2;
		} else if (next->data % 3 == 0) {
			next->data = 3;
		}
		list->next = next;
		list = next;
	}
	
	remove_duplicates(head);
	
	while (head != nullptr) {
		printf("%d\n", head->data);
		head = head->next;
	}
	
	return 0;
}