import sys
import collections
n=int(raw_input())
ans=collections.deque()
while n:
    n-=1
    s=sys.stdin.readline().rstrip().split(' ')
    if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        try:
            ans.remove(s[1])
        except:
            pass
sys.stdout.write(' '.join(ans))
print import sys sys import collections collections n=int(raw_input()) n int(raw_input()) int raw_input() raw_input ans=collections.deque() ans collections.deque() collections.deque collections deque while n:
    n-=1
    s=sys.stdin.readline().rstrip().split(' ')
    if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        try:
            ans.remove(s[1])
        except:
            pass n n-=1 n 1 s=sys.stdin.readline().rstrip().split(' ') s sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split ' ' if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        try:
            ans.remove(s[1])
        except:
            pass s[0][0]=='i' s[0][0] [0] s 0 0 'i' ans.appendleft(s[1]) ans.appendleft ans appendleft s[1] s 1 elif s[0][-3]=='r':
        ans.popleft()
     s[0][-3]=='r' s[0][-3] [0] s 0 -3 'r' ans.popleft() ans.popleft ans popleft elif s[0][-3]=='a':
        ans.pop()
     s[0][-3]=='a' s[0][-3] [0] s 0 -3 'a' ans.pop() ans.pop ans pop try:
            ans.remove(s[1])
        except:
            pass except:
            pass ans.remove(s[1]) ans.remove ans remove s[1] s 1 sys.stdout.write(' '.join(ans)) sys.stdout.write sys.stdout sys stdout write ' '.join(ans) ' '.join ' ' join ans print n-=1 1 n ans=collections.deque() collections.deque() ans s=sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split(' ') s n=int(raw_input()) int(raw_input()) n
import sys
import collections
n=int(raw_input())
ans=collections.deque()
while n:
    n-=1
    s=sys.stdin.readline().rstrip().split(' ')
    if s[0][0]=='i':
        ans.appendleft(s[1])
    elif s[0][-3]=='r':
        ans.popleft()
    elif s[0][-3]=='a':
        ans.pop()
    else:
        try:
            ans.remove(s[1])
        except:
            pass
sys.stdout.write(' '.join(ans))
print