#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
using ULL = unsigned long long int;
using LD = long double;
#define int LL
// #define double LD
template <typename T> using V = std::vector<T>;
using VI = V<int>;
using VVI = V<V<int>>;
using VVVI = V<V<V<int>>>;
using VD = V<double>;
using VVD = V<V<double>>;
#define PB push_back
template <typename T1, typename T2> using P = std::pair<T1, T2>;
template <typename T> using PI = P<int, T>;
using PII = PI<int>;
using PIS = PI<std::string>;
#define MP std::make_pair
#define F first
#define S second
#define FOR(I,A,B) for(int I=int(A); I<int(B); ++I)
#define FORR(I,A,B) for(int I=int(A); I>int(B); --I)
#define REP(I,B) FOR(I,0,B)
#define ALL(A) (A).begin(), (A).end()
constexpr int kMOD = 1e9+7;
const double kPI = std::acos(-1);
struct Read {
	int operator()(void) {
		int d;
		std::cin >> d;
		return d;
	}
}read;
struct ReadReal {
	double operator()(void) {
		double d;
		std::cin >> d;
		return d;
	}
}readR;
struct ReadString {
	std::string operator()(void) {
		std::string s;
		std::cin >> s;
		return s;
	}
}readS;
struct ReadEof {
	bool operator()(void) {
		return std::cin.eof();
	}
}readEof;
struct Print {
	void operator()(void) {
		std::cout << " ";
	}
	void operator()(double lf) {
		std::cout << std::fixed << std::setprecision(16) << lf;
	}
	template <typename T> void operator()(T t) {
		std::cout << t;
	}
	template <typename T1, typename T2>
	void operator()(const std::pair<T1, T2> &pair, const std::string &sep = ":") {
		std::cout << pair.first << sep << pair.second;
	}
	template <typename T>
	void operator()(T begin, T end, const std::string &sep = " ") {
		if (begin == end) return;
		Print()(*begin);
		for(auto it = ++begin;  it != end; ++it) {
			Print()(sep);
			Print()(*it);
		}
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		Print()(v.cbegin(), v.cend(), sep);
	}
	template <typename T>
	void operator()(std::initializer_list<T> list, const std::string &sep = " ") {
		Print()(list.begin(), list.end(), sep);
	}
}print;
struct Println {
	void operator()(void) {
		std::cout << std::endl;
	}
	void operator()(double lf) {
		Print()(lf);
		Println()();
	}
	template <typename T> void operator()(T t) {
		Print()(t);
		Println()();
	}
	template <typename T1, typename T2>
	void operator()(const std::pair<T1, T2> &pair, const std::string &sep = ":") {
		Print()(pair, sep);
		Println()();
	}
	template <typename T>
	void operator()(T begin, T end, const std::string &sep = " ") {
		Print()(begin, end, sep);
		Println()();
		return;
	}
	template <typename T>
	void operator()(const std::vector<T> &v, const std::string &sep = " ") {
		Print()(v.cbegin(), v.cend(), sep);
		Println()();
	}
	template <typename T>
	void operator()(std::initializer_list<T> list, const std::string &sep = " ") {
		Print()(list.begin(), list.end(), sep);
		Println()();
	}
}println;

struct Node {
	int Key;
	shared_ptr<Node> Prev;
	shared_ptr<Node> Next;
};
class DoublyLinkedList {
public:
	DoublyLinkedList(void):m_Node(){
	}
	void Print() {
		if(m_Node) {
			print(m_Node->Key);
		}
		for (auto node = m_Node->Next; node; node = node->Next) {
			print(" ");
			print(node->Key);
		}
		println();
	}
	void DeleteKey(int key) {
		DeleteNode(SearchKey(key));
	}

	void InsertKey(int key) {
		auto node = make_shared<Node>();
		node->Key = key;
		if (!m_Node) {
			m_NodeLast = m_Node = node;
		} else {
			node->Next = m_Node;
			m_Node->Prev = node;
			m_Node = node;
		}
	}
	void DeleteFirst() {
		if (!m_Node) return;
		if (!m_Node->Next) {
			m_Node.reset();
			m_NodeLast.reset();
		} else {
			auto node = m_Node;
			m_Node = m_Node->Next;
			node->Next.reset();
			m_Node->Prev.reset();
		}
	}
	void DeleteLast() {
		if (!m_Node) return;
		if (!m_Node->Next) {
			m_Node.reset();
			m_NodeLast.reset();
			return;
		} else {
			auto node = m_NodeLast;
			m_NodeLast = m_NodeLast->Prev;
			node->Prev.reset();
			m_NodeLast->Next.reset();
		}
	}
private:
	shared_ptr<Node> m_Node;
	shared_ptr<Node> m_NodeLast;
	void DeleteNode(shared_ptr<Node> node) {
		if (!node) return;
		if (!node->Prev) {
			DeleteFirst();
		} else if(!node->Next) {
			DeleteLast();
		} else {
			node->Prev->Next = node->Next;
			node->Next->Prev = node->Prev;
			node->Next.reset();
			node->Prev.reset();
		}
	}
	shared_ptr<Node> SearchKey(int key) {
		auto node = m_Node;
		while(node) {
			if (node->Key == key) break;
			node = node->Next;
		}
		return node;
	}
};

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int size = read();
	DoublyLinkedList list;
	REP(i, size) {
		auto command = readS();
		if (command == "insert") {
			auto key = read();
			list.InsertKey(key);
		} else if (command == "delete") {
			auto key = read();
			list.DeleteKey(key);
		} else if (command == "deleteFirst") {
			list.DeleteFirst();
		} else if (command == "deleteLast") {
			list.DeleteLast();
		}
	}
	list.Print();
	return 0;
}



Measured memory_bytes: 65628