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.InputMismatchException;
import java.util.Random;

import static java.lang.Math.pow;

public class Solution implements Runnable
{
    static int inf=Integer.MAX_VALUE;
    static int mininf=Integer.MIN_VALUE;
    static int  mod=(int) pow(10,9)+7;



    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        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 String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            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 long nextLong()
        {
            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 double nextDouble()
        {
            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 * pow(10, nextInt());
                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 * pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            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 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);
        }

    }

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Solution(),"Cf634d",1<<27).start();
    }
    // **just change the name of class from Main to reuquired**
    public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int n=in.nextInt();
        String str=in.next();
        int[] map=new int[10];
        for (int i=1;i<=9;i++){
            map[i]=in.nextInt();
        }
        char[] temp=str.toCharArray();
            for (int i=0;i<temp.length;i++){
                boolean found=false;
                if (Character.getNumericValue(temp[i])<map[Character.getNumericValue(temp[i])]){
                    int j=i;
                    found=true;
                    while ( j<temp.length&& Character.getNumericValue(temp[j])<=map[Character.getNumericValue(temp[j])]){
                        temp[j]=(char)(map[Character.getNumericValue(temp[j])]+'0');
                        j++;

                    }
                    break;
                }
                if (found){
                    break;

                }
            }


       w.println(String.valueOf(temp));//464563457334873 464563457334873 71222655  78444655 78444677





        System.out.flush();
        w.close();
    }

    public int max(int a,int b){ // max value
        return (Math.max(a,b));
    }
    static void shuffleArray(int[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }

    static int min(int a,int b){ // min value
        return Math.min(a,b);
    }
    public long log(float number , int base){ //get log
        return (long) Math.floor((Math.log(number) / Math.log(base)));
    }
    public long gcd(long a , long b){
        if (b==0){
            return a;
        }
        return gcd(b , a%b);
    }
    public void print2d(long a[][] , PrintWriter out){// print 2d matrix
        for(int i=0;i<a.length;i++){
            for(int j=0;j<a[i].length;j++)
                out.print(a[i][j] + " ");
            out.println();
        }
        out.println();
    }
    public void swap(int a[] , int p1 , int p2){//swap
        int x = a[p1];
        a[p1] = a[p2];
        a[p2] = x;
    }
    public long po(long a , long b , long res){ //power
        if(b == 0)
            return res;
        if(b==1)
            return res*a;
        if(b%2==1){
            res *= a;
            b--;
        }
        return po(a*a , b/2 , res);
    }
    public int [][] matrixMultiply(int a[][] , int b[][]){ // matrix multiply
        int r1 = a.length;
        int c1 = a[0].length;
        int c2 = b[0].length;
        int c[][] = new int[r1][c2];
        for(int i=0;i<r1;i++){
            for(int j=0;j<c2;j++){
                for(int k=0;k<c1;k++)
                    c[i][j] += a[i][k]*b[k][j];
            }
        }
        return c;
    }

}