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

import java.io.*;
import java.util.*;


public class codeforces2 {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
//        Scanner scan = new Scanner(System.in);
        int tc = 1;
        for (int rep = 0; rep < tc; rep++) {
            int N = sc.ni();
            char[] ref = sc.next().toCharArray();
            Map<Character, Integer> map = new HashMap();
            for (int i = 1; i <= 9; i++) {
                map.put(Integer.toString(i).charAt(0), sc.ni());
            }
            for (int i = 0; i < ref.length; i++) {
                int replaceMeWithThis = map.get(ref[i]);
                int curr = charint(ref[i]);
                if (replaceMeWithThis > curr) {
                    ref[i] = Integer.toString(replaceMeWithThis).charAt(0);
                    for (int j = i+1; j < ref.length; j++) {
                        int challenge = map.get(ref[j]);
                        int now = charint(ref[j]);
                        if (challenge < now) {
                            break;
                        }
                        else {
                            ref[j] = Integer.toString(challenge).charAt(0);
                        }
                    }
                    break;
                }
                
            }
            StringBuilder sb = new StringBuilder();
            for (char c : ref) sb.append(c);
            pw.println(sb.toString());
        }
        pw.close();
    }
    public static int solve(long[] nums) {
        return 5;
    }
      
    static int charint(char c) {
        return Integer.parseInt(String.valueOf(c));
    }
    static long pow(long num, long exp, long mod){
        long ans=1;
        for(int i=1;i<=exp;i++){
            ans=(ans*num)%mod;
        }
        return ans;
    }
    static boolean isPrime(int n)
    {
 
        // Check if number is less than
        // equal to 1
        if (n <= 1)
            return false;
 
        // Check if number is 2
        else if (n == 2)
            return true;
 
        // Check if n is a multiple of 2
        else if (n % 2 == 0)
            return false;
 
        // If not, then just check the odds
        for (int i = 3; i <= Math.sqrt(n); i += 2) 
        {
            if (n % i == 0)
                return false;
        }
        return true;
    }
    static int gcd(int a, int b)
    {
        if (a == 0)
            return b; 
        return gcd(b % a, a); 
    }
     
    // method to return LCM of two numbers
    static int lcm(int a, int b)
    {
        return (a / gcd(a, b)) * b;
    }
    public static void sort(int[] arr) {
        Random rgen = new Random();
        for (int i = 0; i < arr.length; i++) {
            int r = rgen.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[r];
            arr[r] = temp;
        }
        Arrays.sort(arr);
    }
 
    public static void sort(long[] arr) {
        Random rgen = new Random();
        for (int i = 0; i < arr.length; i++) {
            int r = rgen.nextInt(arr.length);
            long temp = arr[i];
            arr[i] = arr[r];
            arr[r] = temp;
        }
        Arrays.sort(arr);
    }
    /* */
    //printing methods
    /* */
    //WOW!
    /* */
    public static void printArr(PrintWriter pw, int[] arr) {
        StringBuilder sb = new StringBuilder();
        for (int x : arr) {
            sb.append(x + "");
        }
        sb.setLength(sb.length() - 1);
        pw.println(sb.toString());
    }
    public static void printArr2d(PrintWriter pw, int[][] arr) {
        StringBuilder sb = new StringBuilder();
        for (int[] row : arr) {
            for (int x : row) {
                sb.append(x + " ");
            }
            sb.setLength(sb.length() - 1);
            sb.append("\n");
        }
        sb.setLength(sb.length() - 1);
        pw.println(sb.toString());
    }
}
class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in), 32768);
        st = null;
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int ni() {
        return Integer.parseInt(next());
    }

    int[] intArray(int N) {
        int[] ret = new int[N];
        for (int i = 0; i < N; i++)
            ret[i] = ni();
        return ret;
    }

    long nl() {
        return Long.parseLong(next());
    }

    long[] longArray(int N) {
        long[] ret = new long[N];
        for (int i = 0; i < N; i++)
            ret[i] = nl();
        return ret;
    }

    double nd() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
class UnionFind {
    int size;
    private int[] id;
    public UnionFind(int size) {
        this.size = size;
        id = new int[size];
        for (int i = 0; i < id.length; i++) {
            id[i] = i;
        }
    }
    public int find(int a) {
        if (id[a] != a) {
            id[a] = find(id[a]);
        }
        return id[a];
    }
    public void union(int a, int b) {
        int r1 = find(a);
        int r2 = find(b);
        if (r1 == r2) return;
        size--;
        id[r1] = r2;
    }
    @Override
    public String toString() {
        return Arrays.toString(id);
    }
}
