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.util.*;
import java.io.*;
import java.util.regex.*;
import java.math.BigInteger;

public class Codeforces{

	static class MyScanner{
		BufferedReader br;
		StringTokenizer st;

		MyScanner(FileReader fileReader){
			br = new BufferedReader(fileReader);
		}

		MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

		char nc(){
			return nn().charAt(0);
		}

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

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

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

		int[] niArr0(int n){
			int[] ar = new int[n];
			for(int i = 0; i < n; i++) ar[i] = ni();
			return ar;
		}

		int[] niArr1(int n){
			int[] ar = new int[n + 1];
			for(int i = 1; i <= n; i++) ar[i] = ni();
			return ar;
		}

		long[] nlArr0(int n){
			long[] ar = new long[n];
			for(int i = 0; i < n; i++) ar[i] = nl();
			return ar;
		}
	}

	public static <T> void mprintln(T ... ar){
		for(T i: ar) out.print(i + " ");
		out.println();
	}

	private static PrintWriter out;

	public static void main(String[] args) throws FileNotFoundException{

		// Input from file
		// File inputFile = new File("JavaFile.txt");
		// File outputFile = new File("JavaOutputFile.txt");
		// FileReader fileReader = new FileReader(inputFile);
		// Here it ends

		MyScanner sc = new MyScanner();
		// MyScanner sc = new MyScanner(fileReader);

		out = new PrintWriter(new BufferedOutputStream(System.out)); // Output to console
		// out = new PrintWriter(new PrintStream(outputFile)); // Output to file

		getAns(sc);

		out.close();
	}

	private static void getAns(MyScanner sc){
		int n = sc.ni();
		char[] ar = sc.nn().toCharArray();
		int[] map = sc.niArr1(9);
		
		int i = 0;
		
		for(i = 0; i < n; i++){
			int cur = ar[i] - '0';
			if(cur < map[cur]) break;
			out.print(ar[i]);
		}
		
		while(i < n){
			int cur = ar[i] - '0';
			if(cur > map[cur]) break;
			out.print(map[cur]);
			i++;
		}
		
		while(i < n){
			out.print(ar[i]);
			i++;
		}
	}
}
