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
/*      MOHD SADIQ        */


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.ArrayList;

public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private  long longVal() throws IOException{
        return Long.parseLong(br.readLine().trim());
    }
    private  int intVal() throws IOException{
        return Integer.parseInt(br.readLine().trim());
    }
    private  double doubleVal() throws IOException{
        return Double.parseDouble(br.readLine().trim());
    }
    private  int[] intArr() throws IOException{
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        return a;
    }
    private  long[] longArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(s[i]);
        }
        return a;
    }
    private  double[] doubleArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        double[] a = new double[n];
        for (int i = 0; i < n; i++) {
            a[i] = Double.parseDouble(s[i]);
        }
        return a;
    }
    private String[] stringArr() throws IOException{
        String[] s = br.readLine().trim().split(" ");
        return s;
    }
    private  char[] charArr() throws IOException{
        return br.readLine().trim().toCharArray();
    }

    private static boolean check(String s){
        for(int i=0;i<s.length()-1;i++){
            if(s.charAt(i)<s.charAt(i+1)){
                return true;
            }
        }
        return false;
    }

    private static String solve() throws IOException {

        Main obj = new Main();
        int n = obj.intVal();
        char[] c = obj.charArr();
        char[] x = br.readLine().trim().replace(" ","").toCharArray();
        boolean ch = true;
        for(int i=0;i<n;i++){
            if(x[c[i]-'1']>c[i]){
//                System.out.println(ch);
                ch = false;
            }
//            System.out.println(x[c[i]-'0']+" "+c[i]);
//            System.out.println(ch);
            if(!ch){
                while (i<n && x[c[i]-'1']>=c[i]){
                    c[i] = x[c[i]-'1'];
                    i++;
                }
                break;
            }
        }
        return new String(c)+"";
    }


    public static void main(String[] args) throws IOException {
        Main ob = new Main();
//        int total_test_case = ob.intVal();
        int total_test_case = 1;
        StringBuffer ans = new StringBuffer();
        String k ;
        for(int test_case =0;test_case<total_test_case;test_case++){
            k = Main.solve();
//            System.out.println(k);
            ans.append(k+"");
        }
        System.out.print(ans);
    }
}