class DoublyLinkedList {
  constructor() {
    this.list = {
      next: null,
    };
    this.first = null;
    this.last = null;
  }

  insert(value) {
    if (this.first === null) {
      this.list = {
        next: {
          prev: null,
          value: value,
          next: null,
        },
      };
      this.first = this.list.next;
      this.last = this.list.next;
    } else {
      const secondNode = this.list.next;
      this.list = {
        next: {
          prev: null,
          value: value,
          next: secondNode,
        },
      };
      secondNode.prev = this.list.next;
      this.first = this.list.next;
    }
  }

  remove(value) {
    let node = this.list.next;
    while (true) {
      if (node === null || node.value === value) {
        break;
      }
      node = node.next;
    }
    this.removeNode(node);
  }

  removeNode(node) {
    if (!node) return;

    if (node.prev) {
      node.prev.next = node.next;
    } else {
      // node is first
      this.first = node.next;
      this.list.next = this.first;
    }

    if (node.next) {
      node.next.prev = node.prev;
    } else {
      // node is last;
      this.last = node.prev;
    }
    
    node = null;
  }

  deleteFirst() {
    this.removeNode(this.first);
  }

  deleteLast() {
    this.removeNode(this.last);
  }

  print() {
    const str = [];
    let node = this.first;
    while (!!node) {
      str.push(node.value);
      node = node.next;
    }
    console.log(str.join(' '));
  }
}

const proc = (arr) => {
  const list = new DoublyLinkedList();

  arr.shift(); // for N
  arr.forEach((element) => {
    const [cmd, v] = element.split(' ');

    if (cmd === 'insert') {
      list.insert(v);
      return;
    }

    if (cmd === 'delete') {
      list.remove(v);
      return;
    }

    if (cmd === 'deleteFirst') {
      list.deleteFirst();
      return;
    }

    if (cmd === 'deleteLast') {
      list.deleteLast();
      return;
    }
  });

  list.print();
};

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    proc(inputString);
});







