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
###########################################
#  Author : Uranux   
#  Created On : Wed Apr 24 2019
#  File : B.py
###########################################

def input_s():
    return raw_input()

def input_i():
    return int(raw_input())

def input_2_i():
    arr = map(int, raw_input().split())
    return arr[0], arr[1]

def input_3_i():
    arr = map(int, raw_input().split())
    return arr[0], arr[1], arr[2]

def input_i_array():
    return map(int, raw_input().split())

def get_presum(n, arr):
    presum = [arr[0]]
    for i in range(1, n):
        presum.append(presum[i - 1] + arr[i])
    return presum

def calc(n, s, arr):
    ans = []
    start = False
    start_pos = -1
    end_pos = -1
    for i in range(n):
        val = ord(s[i]) - ord('0')
        if arr[val - 1] > val:
            if not start:
                start = True
                start_pos = i
            end_pos = i
        elif arr[val - 1] == val:
            if start:
                end_pos = i
        else:
            if start:
                break
    
    for i in range(n):
        val = ord(s[i]) - ord('0')
        if start_pos <= i <= end_pos:
            ans.append(arr[val - 1])
        else:
            ans.append(val)

    return ''.join(map(str, ans))
    

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

n = input_i()
s = input_s()
arr = input_i_array()

print calc(n, s, arr)

