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.lang.*;
import java.io.*;
import java.util.concurrent.LinkedBlockingQueue;
public class Codechef
{    static String arr[];
    static ArrayList<Integer>graph[];
    static int size[];
    static boolean deleted[];
    static boolean vis[];
    static int MAX = 500001;
    static int a,b,n,maxa;
    static int cache[];
	public static void main (String[] args) throws java.lang.Exception
	{
	   // InputReader input = new InputReader(System.in);
	     OutputWriter out = new OutputWriter(System.out);
	     Scanner input = new Scanner(System.in);
	     int n = input.nextInt();
	     input.nextLine();
	      String s = input.nextLine();
	      int arr[] = new int[10];
	      for(int i =1;i<=9;i++)arr[i] = input.nextInt();
	      char c[] = s.toCharArray();
	      int index =0;
	      for(int i =0;i<n;i++){
	          int val = c[i]-'0';
	          if(val<arr[val]){
	              index = i;
	              break;
	          }
	          
	      }
	      for(int i = index;i<n;i++){
	          int val = c[i] - '0';
	          if(val<=arr[val])c[i] = (char)('0'+arr[val]);
	          else break;
	      }
	      
	      for(char it:c)System.out.print(it);
	    
	    
	    
	    
	      
	}
	public static void useB(int bit){
	    if(bit == 1)a = Math.min(a+1,maxa);
	    b--;
	} 
	public  static void useA(){
	    a--;
	}
	public static void centroid_decomposition(){
	    decompose(0);
	}
	public static void decompose(int v){
	    calculateSubtreeSize(v);
	    int centroid = findCentroid(v,size[v]);
	    System.out.print((centroid+1)+" ");
	    calculateSubtreeSize(centroid);
	    deleted[centroid] = true;
	    for(int child:graph[v]){
	        if(deleted[child])continue;
	        decompose(child);
	    }
	}
	public static int findCentroid(int v,int total){
	    for(int child:graph[v]){
	        if(vis[child] || deleted[child])continue;
	        if(size[child]>total/2){
	            findCentroid(child,size[child]);
	        }
	    }
	    return v;
	}
	public static void calculateSubtreeSize(int v){
	    size[v] = 1;
	    vis[v] = true;
	    for(int child:graph[v]){
	        if(vis[child] || deleted[v])continue;
	        calculateSubtreeSize(child);
	        size[v]+=size[child];
	    }
	}
}
class Query{
    String s = null;
    public Query(String s){
        this.s = s;
    }
}
class Node{
    int id,r,l;
    public Node(int r,int l,int id){
        this.r = r;
        this.l = l;
        this.id = id;
    }
}
 class InputReader{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
		
		public int read() {
			if (numChars == -1) {
				throw new InputMismatchException();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}
		
		public int readInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		
		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}
		
		public double readDouble() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E') {
					return res * Math.pow(10, readInt());
				}
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E') {
						return res * Math.pow(10, readInt());
					}
					if (c < '0' || c > '9') {
						throw new InputMismatchException();
					}
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
		
		public long readLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9') {
					throw new InputMismatchException();
				}
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
		
		public boolean isSpaceChar(int c) {
			if (filter != null) {
				return filter.isSpaceChar(c);
			}
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
		
		public String next() {
			return readString();
		}
		
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
	
 class OutputWriter {
		private final PrintWriter writer;
		
		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}
		
		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}
		
		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0) {
					writer.print(' ');
				}
				writer.print(objects[i]);
			}
			writer.flush();
		}
		
		public void printLine(Object... objects) {
			print(objects);
			writer.println();
			writer.flush();
		}
		
		public void close() {
			writer.close();
		}
		
		public void flush() {
			writer.flush();
		}
	}
	   
//********************************************************************************************************************************
//////////////////////////////////NOTESSS//////////////////////////////////////////////////////////////////////
/*remember substring length you are dealing with take only those substrings
chain like pattern -> linked list (or) to from Arrays
finding degree can be done during input scanning itself(ok&=true:false flag trick)
longest subsquence can be solved in O(n) itself incase of consecutive numbers why try all subsequence go o dp[i-1]
(*******consecutive numberssssss*********)
initialize all global variables and collection ds
swapping changes the arr so make sure initialize with the original again(careful from where to start after swapping)
missing out character when comparing ==0 instead of =='0'
keep going until a condition and start off from first ****stack***
meet in the middle algo
one dfs call will tell u the dfs of all nodes
2d prefix array for max occurence of number in a range.also storing positions in case of duplicate numbers can
help bring down the complexity to o(N) and considering ranges based on positions
 
when u want to apply changes for a range PREFIX SUMS
want to know number of elements in  range use preifx sum (or)l,r pointer from a particular point
when u want to use binary search check if problem remains the same even after splitting to two parts
checking for range can be done using binary search i.e can this range stisfy a particular condition if so
include more elements to tha range from left to right or right to left depending on the problem
 
parity can also be checked to make elements equal(when making elements equal check what is allowed and what not
and how to achieve it what are the result sets after applying the allowed moves like add 1 add 2.....)
 
each step u want max range incase if its equal u select upon the condition---> what DS= ***PRIORITY QUEUE***
*/