# Original solution
class Node():
    key = 0
    def __init__( self,  key ):
        self.key = key
        self.next = -1
        self.pre = -1

    def insert( self, othernode ): # othernodeにはinsert前の先頭のノードを入れる
        self.next = othernode
        othernode.pre = self
        return self

    def delete( self, x ): #先頭ノードで実行
        FirstNode = self
        if self.key == x:
            if self.pre == -1:
                self.next.pre = -1
                FirstNode = self.next
            else :
                self.pre.next = self.next
                self.next.pre = self.pre
        else:
            if self.next != -1:
                self.next.delete( x )
        return FirstNode

    def printNodes( self ): #先頭ノードで実行
        if self.next.next != -1:
            print( str( self.key ), end=" " )
            self.next.printNodes()
        elif self.next != -1:
            print( str( self.key ), end="\n" )

    def deleteFirst( self ):
        self.next.pre = -1
        return self.next #新しい先頭ノードを返す

    def deleteLast( self ):
        if self.next != -1:
            self.next.deleteLast()
        else :
            self.pre.next = -1


def main():
    n = int( input() )
    commands = []
    vals = []
    for i in range(n):
        tmp = input().split()
        tmp.append( 0 )
        commands.append( tmp[0] )
        vals.append( int(tmp[1]) )

    FirstNode = Node( None )
    for i in range(n):
        if commands[i] == "insert":
            TmpNode = Node( vals[i] )
            FirstNode = TmpNode.insert( FirstNode )
        elif commands[i] == "delete":
            FirstNode = FirstNode.delete( vals[i] )
        elif commands[i] == "deleteFirst":
            FirstNode = FirstNode.deleteFirst()
        elif commands[i] == "deleteLast":
            FirstNode.deleteLast()
        else :
            print("command error!")

    FirstNode.printNodes()

if __name__ == '__main__':
    main()



# Optimized solution
class Node():
    key = 0
    def __init__( self,  key ):
        self.key = key
        self.next = -1
        self.pre = -1

    def insert( self, othernode ): # othernodeにはinsert前の先頭のノードを入れる
        self.next = othernode
        othernode.pre = self
        return self

    def delete( self, x ): #先頭ノードで実行
        FirstNode = self
        if self.key == x:
            if self.pre == -1:
                self.next.pre = -1
                FirstNode = self.next
            else :
                self.pre.next = self.next
                self.next.pre = self.pre
        else:
            if self.next != -1:
                self.next.delete( x )
        return FirstNode

    def printNodes( self ): #先頭ノードで実行
        if self.next.next != -1:
            print( str( self.key ), end=" " )
            self.next.printNodes()
        elif self.next != -1:
            print( str( self.key ), end="\n" )

    def deleteFirst( self ):
        self.next.pre = -1
        return self.next #新しい先頭ノードを返す

    def deleteLast( self ):
        if self.next != -1:
            self.next.deleteLast()
        else :
            self.pre.next = -1


def main():
    n = int( input() )
    FirstNode = Node( None )
    for i in range(n):
        tmp = input().split()

        if tmp[0] == "insert":
            TmpNode = Node( tmp[1] )
            FirstNode = TmpNode.insert( FirstNode )
        elif tmp[0] == "delete":
            FirstNode = FirstNode.delete( tmp[1] )
        elif tmp[0] == "deleteFirst":
            FirstNode = FirstNode.deleteFirst()
        elif tmp[0] == "deleteLast":
            FirstNode.deleteLast()
        else :
            print("command error!")

    FirstNode.printNodes()

if __name__ == '__main__':
    main()