You are given a long decimal number a consisting of n digits from 1 to 9. You also have a function f that maps every digit from 1 to 9 to some (possibly the same) digit from 1 to 9.

You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in a, and replace each digit x from this segment with f(x). For example, if a = 1337, f(1) = 1, f(3) = 5, f(7) = 3, and you choose the segment consisting of three rightmost digits, you get 1553 as the result.

What is the maximum possible number you can obtain applying this operation no more than once?

Input

The first line contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of digits in a.

The second line contains a string of n characters, denoting the number a. Each character is a decimal digit from 1 to 9.

The third line contains exactly 9 integers f(1), f(2), ..., f(9) (1 ≤ f(i) ≤ 9).

Output

Print the maximum number you can get after applying the operation described in the statement no more than once.

Examples

Input


4
1337
1 2 5 4 6 6 3 1 9


Output


1557


Input


5
11111
9 8 7 6 5 4 3 2 1


Output


99999


Input


2
33
1 1 1 1 1 1 1 1 1


Output


33
l = input()
n = input()
map_str = input()


# l = 4
# n = 9129879172126
#map_str = "1 2 3 4 5 5 9 8 9"
#map_str = "6 2 9 2 4 3 9 6 4"


#l = int(l)
#n = int(n)
map_str = map_str.split(' ')

num_change = 0

def f(n_temp,subsegment):
	n_ = [str(x) for x in str(n_temp)]	############# convert string to list of element
	for i in subsegment:
		k = int(i)
		n_[k] = map_str[int(n_[k])-1]
	return "".join(n_)				############# convert list of element to string


def f1(n_temp):
	n_ = [str(x) for x in str(n_temp)]	############# convert string to list of element
	for k in range(0,len(n_temp)):
		n_[k] = map_str[int(n_[k])-1]
	return "".join(n_)				############# convert list of element to string
# def change_value(n_temp):
# 	n__ = [int(x) for x in str(n_temp)]

# 	max_ = int(n_temp)
# 	l_ = len(n_temp)

# 	for i in range(0,l_):
# 		for k in range(0,l_-i):
# 			str_ = ""
# 			for j in range(k,k+i+1):
# 				if(n__[j] >= int(map_str[n__[j]-1])):
# 					str_ = None 
# 					break
# 				str_+=str(j)
# 			if str_ != None:
# 				k = int(f(n_temp,str_))
# 				if k > max_: max_ = k
# 	return max_

# def change_value(n_temp):
# 	n__ = [int(x) for x in str(n_temp)]

# 	max_ = int(n_temp)
# 	l_ = len(n_temp)

# 	for i in range(0,l_):
# 		for k in range(0,l_-i):
# 			str_ = ""
# 			for j in range(k,k+i+1):
# 				if(n__[j] >= int(map_str[n__[j]-1])):
# 					str_ = None 
# 					break
# 				str_+=str(j)
# 			if str_ != None:
# 				k = int(f(n_temp,str_))
# 				if k > max_: max_ = k
# 	return max_

# def find_max(n):
# 	global num_change
# 	n__ = [int(x) for x in str(n)]
# 	l_ = len(n__)
# 	if n == '': return ''
# 	if l_ == 1 : 
# 		return n if int(n) >= int(map_str[int(n)-1]) else int(map_str[int(n)-1])

# 	pivot = -1
# 	for i in range(0,l_):
# 		if (n__[i] >= int(map_str[n__[i]-1])):
# 			pivot = i
# 			break

# 	if pivot == -1:
# 		return str(change_value(n))
# 	if num_change == 1:
# 		return n
# 	if pivot == 0:
# 		return n[0]+ str(find_max(n[1:])) # bỏ phần tử đầu
# 	else:
# 		max_change_value = change_value(n[0:pivot])

# 		if max_change_value < 10:
# 			num_change = 1
# 			return str(max_change_value)+str(find_max(n[pivot:]))#n[pivot:]
# 		if max_change_value == int(n[0:pivot]):
# 			if num_change == 1:
# 				return n
# 			return n[0:pivot+1] + str(find_max(n[pivot+1:]))
# 		num_change = 1
# 		return str(max_change_value)+str(find_max(n[pivot:])) #n[pivot:]
# 	print(pivot)			

#find_max(n)
#num_change

def find_max2(n):
	global num_change
	n__ = [int(x) for x in str(n)]
	l_ = len(n__)
	if n == '': return ''
	if l_ == 1 : 
		return n if int(n) >= int(map_str[int(n)-1]) else int(map_str[int(n)-1])


	pivot = -1
	# tìm vị trí mà ở đó ko thay được 
	for i in range(0,l_):
		if (n__[i] > int(map_str[n__[i]-1])):
			pivot = i
			break
	if pivot == -1:
		return str(f1(n))
	if pivot == 0:
		k = str(n[0]) if int(n[0]) > int(map_str[int(n[0])-1]) else str(map_str[n[0]-1])
		if k == str(n[0]) and num_change == 0:
			return str(k) + str(find_max2(n[1:]))
		return str(k)+ str(n[1:])
	else:
		max_change_value = f1(n[0:pivot])
		if max_change_value == n[0:pivot]: # =
			if num_change == 1:
				return n
			return n[0:pivot]+ find_max2(n[pivot:])
		else: # <
			num_change = 1
			return max_change_value + find_max2(n[pivot:])



#print(find_max2("912987917212692864314789"))
print(find_max2(str(n)))
#print(find_max2("87"))
#6 2 9 2 4 3 9 6 4