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
/*
 * Remember a 6.0 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience. 
 * I Never Give Up.
 * I will become Candidate Master.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;

import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=1000000000+7;//10^9+7
	private static final int N=100000+7; //10^5+7
//	private static final double EPS=1e-9;
//	private static final int LIM=26;
//	private static final double PI=3.1415;
	private static ArrayList<Integer> v[]=new ArrayList[N];
//	private static int color[]=new int[N];
	private static boolean mark[]=new boolean[N];
//	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//	private static ArrayList<Pair> v[]=new ArrayList[N];
	private static long powmod(long x,long n){
		if(n==0||x==0)return 1;
		else if(n%2==0)return(powmod((x*x)%MOD,n/2));
		else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
	private static void shuffle(long [] arr) {
		for (int i = arr.length - 1; i >= 2; i--) {
			int x = new Random().nextInt(i - 1);
	        long temp = arr[x];
	        arr[x] = arr[i];
	        arr[i] = temp;
	    }
	 }
//	private static long gcd(long a, long b){
//		if(b==0)return a;
//		return gcd(b,a%b);
//	}
//	private static boolean check(int x,int y){
//		if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true;
//		return false;
//	}
//	static class Node{
//		int left;
//		int right;
//		Node(){
//			left=0;
//			right=0;
//		}
//	}
	public static void main(String[] args) throws IOException{
		int n=in.nextInt();
		int ar[]=new int[n];
		int form[]=new int[10];
		String s=in.next();
		for(int i=0;i<n;i++){
			ar[i]=s.charAt(i)-'0';
		}
		for(int i=1;i<=9;i++)
			form[i]=in.nextInt();
		int c=0;
		for(int i=0;i<n;i++){
			if(ar[i]<form[ar[i]]){
				c=ar[i];
				while(i<n&&ar[i]<=form[ar[i]]){
					ar[i]=form[ar[i]];
					i++;
				}
				break;
			}
		}
		for(int i=0;i<n;i++)
			ans.append(ar[i]);
		out.println(ans);
	}
	static class Pair<T> implements Comparable<Pair>{
		int l;
		int r;
		int ind;
		Pair(){
			l=0;
			r=0;
			ind=0;
		}
		Pair(int k,int v,int i){
			l=k;
			r=v;
			ind=i;
		}
//		@Override
//		public int compareTo(Pair o) {
//			if(o.l!=l)return (int) (l-o.l);
//			else return (int)(r-o.r);
//		}
		//Fenwick tree question comparator
		@Override
		public int compareTo(Pair o) {
			if(o.r!=r)return (int) (r-o.r);
			else return (int)(l-o.l);
		}
	}
	static class Reader{
        BufferedReader br;
        StringTokenizer st;
        public Reader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
     
                	st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}