N = int(input())
arr = list(input().split())
visited = [False for i in range(10)]
maxV, minV = '0', '9999999999'
pos = 0
tempArr = []
def dfs(cnt):
global maxV, minV, pos
if cnt == N + 1:
temp = ''.join(map(str, tempArr))
if int(maxV) < int(temp):
maxV = temp
if int(minV) > int(temp):
minV = temp
return
for i in range(10):
if not visited[i]:
if len(tempArr) > 0:
if arr[pos] == '<':
if i > tempArr[-1]:
visited[i] = True
pos += 1
tempArr.append(i)
dfs(cnt + 1)
tempArr.pop()
pos -= 1
visited[i] = False
else:
if i < tempArr[-1]:
visited[i] = True
pos += 1
tempArr.append(i)
dfs(cnt + 1)
tempArr.pop()
pos -= 1
visited[i] = False
else:
visited[i] = True
tempArr.append(i)
dfs(cnt + 1)
tempArr.pop()
visited[i] = False
dfs(0)
print(maxV)
print(minV)
백트랙킹(DFS)