#include <bits/stdc++.h>
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  a.begin(),a.end()

class CommonIO {
public:
  CommonIO() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
  }
  ~CommonIO() {}

  template <class T>
  void scan(T &v) {
      std::cin >> v;
  }
  template <class T, class... Rest>
  void scan(T &v, Rest&... rest) {
      scan(v);
      scan(rest...);
  }

  template <class T>
  void print(T v) {
    std::cout << v;
  }
  template <class T>
  void print(std::vector<T> &v) {
    if (v.size() == 0) return;
    print(*v.begin());
    for (auto it = ++v.begin(); it != v.end(); ++it) {
        print(' ');
        print(*it);
    }
  }
  template <class T>
  void print(std::vector< std::vector<T> > &grid) {
    if (grid.size() == 0) return;
    print(*grid.begin());
    for (auto it = ++grid.begin(); it != grid.end(); ++it) {
      print('\n');
      print(*it);
    }
  }
  template <class T, class... Rest>
    void print(T v, Rest... rest) {
    print(v);
    print(' ');
    print(rest...);
  }

  template <class T>
    void printl(T v) {
    print(v);
    std::cout << '\n';
  }
  template <class T, class... Rest>
    void printl(T v, Rest... rest) {
    print(v);
    print(' ');
    printl(rest...);
  }
  #define original_output(obj) std::ostream& operator<<(std::ostream& stream, const decltype(obj)& obj)
} io;


struct List {
  struct Node {
    int key;
    Node *prev, *next;
  };
  Node *start, *last;

  List() : start(nullptr) {}
  void insert(int key) {
    Node *node = new Node();
    node->key = key;
    if (start == nullptr) {
      node->prev = nullptr;
      node->next = nullptr;
      last = node;
    }
    else {
      node->prev = start->prev;
      node->next = start;
      start->prev = node;
    }
    start = node;
  }
  void del(int key) {
    for (Node *node=start; node!=nullptr; node=node->next) {
      if (node->key == key) {
        if (node->prev != nullptr) node->prev->next = node->next;
        if (node->next != nullptr) node->next->prev = node->prev;
        if (node == start) start = node->next;
        if (node == last) last = node->prev;
        delete node;
        return;
      }
    }
  }
  void deleteFirst() {
    Node *oldStart = start;
    start = start->next;
    if (start != nullptr) start->prev = nullptr;
    if (oldStart == last) last = nullptr;
    delete oldStart;
  }
  void deleteLast() {
    Node *oldLast = last;
    last = last->prev;
    if (last != nullptr) last->next = nullptr;
    if (oldLast == start) start = nullptr;
    delete oldLast;
  }
  void printAll() {
    if (start == nullptr) {
      io.print("\n");
      return;
    }
    io.print(start->key);
    for (Node *node=start->next; node!=nullptr; node=node->next) {
      io.print(" ");
      io.print(node->key);
    }
    io.print("\n");
  }
};

int main() {
  int n; io.scan(n);
  
  List list;
  
  string cmd;
  int key;
  REP(i, n) {
    io.scan(cmd);
    if (cmd == "insert") {
      io.scan(key);
      list.insert(key);
    }
    else if (cmd == "delete") {
      io.scan(key);
      list.del(key);
    }
    else if (cmd == "deleteFirst") {
      list.deleteFirst();
    }
    else if (cmd == "deleteLast") {
      list.deleteLast();
    }
  }
  list.printAll();

  return 0;
}



Measured memory_bytes: 34464