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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

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

		SC scan = new SC();
		StringBuilder sb = new StringBuilder();
		
		int n = scan.nextInt();
		char[] c = scan.nextLine().toCharArray();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = c[i] - '0';
		int[] f = new int[10];
		for (int i = 1; i < 10; i++)
			f[i] = scan.nextInt();
		
		boolean b = false;
		for (int i = 0; i < n; i++) {
			if (f[a[i]] > a[i]) {
				b = true;
				c[i] = (char) ('0' + f[a[i]]);
			}
			if (b && f[a[i]] < a[i])
				break;
		}
		System.out.println(new String(c));
	}
	
	
	static class SC {
		private BufferedReader br;
		private StringTokenizer st;
		
		public SC() throws Exception {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer("");
		}
		
		public String nextLine() throws Exception {
			return br.readLine();
		}
		
		public String next() throws Exception {
			while (!st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		
		public int nextInt() throws Exception {
			return Integer.parseInt(next());
		}
	}
	
	
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new UnknownError();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new UnknownError();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int peek() {
			if (numChars == -1)
				return -1;
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					return -1;
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar];
		}

		public void skip(int x) {
			while (x-- > 0)
				read();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public String nextString() {
			return next();
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public String nextLine() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		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 * Math.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 * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public boolean hasNext() {
			int value;
			while (isSpaceChar(value = peek()) && value != -1)
				read();
			return value != -1;
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

	}

}
