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
"""
- math -
from math import factorial
from math import gcd
from math import pi
large_p = 10**9 + 7
from itertools import accumulate # 累積和
from operator import mul
- other -
from collections import Counter
from itertools import combinations
from itertools import combinations_with_replacement
from itertools import permutations
from operator import itemgetter
from functools import reduce
- list -
from copy import deepcopy
from collections import deque
from heapq import heapify, heappop, heappush
- output -
p2d = lambda x: print(*x, sep="\n")
p2line = lambda x: print(*x, sep=" ")
print(*list1, sep="\n")
- input -
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
= map(int, input().split())
= [tuple(map(int, input().split())) for _ in range(n)]
m = map(int, read().split()) /ab = zip(m, m) /for a, b in ab:
ps = [line.split() for line in readlines()] # inputの最後まで読んでしまうので注意。
n, k, *h = map(int, read().split())
- run -
sys.setrecursionlimit(10**6)
from time import sleep
"""
#ATC06

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    a2 = list(input())
    h = input().split()
    h2 = [0] * 9
    for j1 in range(9):
        h2[j1] = int(h[j1]) > (j1 + 1)
    h22 = [0] * 9
    for j1 in range(9):
        h22[j1] = int(h[j1]) >= (j1 + 1)
    a2i = [int(ae) for ae in a2]
    flag = False
    for i1, a2ie in enumerate(a2i):
        if not flag:
            if h2[a2ie-1]:
                flag = True
                a2[i1] = h[a2ie - 1]
        else:
            if h22[a2ie-1]:
                a2[i1] = h[a2ie - 1]
            else:
                break
    r = "".join(a2)
    print(r)


if __name__ == '__main__':
    main()