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
def get_biggest_number(num, mapping):
    segment_start = False
    segment_done = False
    # import pdb; pdb.set_trace()
    result = list(map(int, num))
    for idx, digit in enumerate(num):
        digit = int(digit)

        if mapping[digit - 1] > digit:
            segment_start = True
            result[idx] = mapping[digit - 1]
        elif mapping[digit - 1] == digit:
            continue
        else:
            if segment_start:
                segment_done = True
                break
    return ''.join(map(str, result))


def another(n, num, mapping):
    # import pdb; pdb.set_trace()
    result = list(map(int, num))
    diff = []
    for d in result:
        diff.append(mapping[d - 1] - d)
    i = 0
    while i < n:
        if diff[i] > 0:
            while i < n and diff[i] >= 0:
                result[i] += diff[i]
                i += 1
            break
        i += 1
    return ''.join(map(str, result))



n = int(input())
num = input()
mapping_list = list(map(int, input().split()))

print(get_biggest_number(num, mapping_list))
# print(another(n, num, mapping_list))


"""
6
133711
9 2 5 4 6 6 3 1 9
"""

def stress_test():
    from random import randint, shuffle
    digits = list(range(1, 10))
    i = 0
    while True:
        num = str(randint(1, 2 * 10**2))
        n = len(num)
        shuffle(digits)

        one = get_biggest_number(num, digits)
        two = another(n, num, digits)

        if one != two:
            print(f'TEST #{i} - FAILED: num - {num}, digits - {digits}. One: {one}, two: {two}')
            break
        else:
            print(f'TEST #{i} - OK')
        
        i += 1

# TEST #0 - FAILED: num - 132, digits - [8, 4, 3, 2, 5, 7, 6, 9, 1]
# stress_test()

"""
3
193
8 1 4 7 3 5 6 2 9
"""