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

public class Main {

	static int INF = 1000000007;
	static int MAX = Integer.MAX_VALUE;
	static int MIN = Integer.MIN_VALUE;

	public static void main(String[] args) {
		// int test = fs.nextInt();
		int test = 1;
		for (int cases = 0; cases < test; cases++) {
			int n = fs.nextInt();
			char ar[] = fs.next().toCharArray();
			HashMap<Integer, Integer> hm = new HashMap<>();
			for (int i = 0; i < 9; i++) {
				hm.put(i + 1, fs.nextInt());
			}
			int i = 0;
			for (; i < n; i++) {
				char ch = ar[i];
				int z = ch - '0';
				int re = hm.get(z);
				if (re > z) {
					break;
				}
			}
			if (i < n) {
				char ch = ar[i];
				int z = ch - '0';
				int re = hm.get(z);
				while (re >= z) {
					ar[i] = (char) (re + '0');
					++i;
					if (i >= n) {
						break;
					}
					ch = ar[i];
					z = ch - '0';
					re = hm.get(z);
				}
			}
			System.out.println(String.valueOf(ar));
		}
	}

	static long lengthOfNumber(long x) {
		long ans = 0;
		while (x > 0) {
			++ans;
			x /= 10;
		}
		return ans;
	}

	static void printArray(int[][] ar, int n) {
		for (int i = 0; i < n; i++) {
			System.out.println(Arrays.toString(ar[i]));
		}
	}

	static long power(long x, long y, long p) {
		long res = 1;
		x = x % p;
		while (y > 0) {
			if (y % 2 == 1)
				res = (res * x) % p;
			y = y >> 1;
			x = (x * x) % p;
		}
		return res;
	}

	static long modInverse(long n, long p) {
		return power(n, p - 2, p);
	}

	static long nCrModPFermat(long n, long r, long p) {
		long ans1 = 1;
		long i = n;
		long k = r;
		while (k > 0) {
			ans1 = mul(ans1, i, p);
			i--;
			k--;
		}
		long ans2 = 1;
		while (r > 0) {
			ans2 = mul(ans2, r, p);
			r--;
		}
		r = modInverse(ans2, p);
		ans1 = mul(ans1, r, p);
		return ans1;
	}

	static long facCalc(long total) {
		long ans = 1;
		for (long i = 2; i <= total; i++) {
			ans = ans * i;
		}
		return ans;
	}

	static long mul(long a, long b, long p) {
		return ((a % p) * (b % p)) % p;
	}

	static void sieve() {
		boolean prime[] = new boolean[101];
		Arrays.fill(prime, true);
		prime[1] = false;
		for (int i = 2; i * i <= prime.length - 1; i++) {
			for (int j = i * i; j <= prime.length - 1; j += i) {
				prime[j] = false;
			}
		}
	}

	public static int[] radixSort(int[] f) {
		return radixSort(f, f.length);
	}

	public static int[] radixSort(int[] f, int n) {
		int[] to = new int[n];
		{
			int[] b = new int[65537];
			for (int i = 0; i < n; i++)
				b[1 + (f[i] & 0xffff)]++;
			for (int i = 1; i <= 65536; i++)
				b[i] += b[i - 1];
			for (int i = 0; i < n; i++)
				to[b[f[i] & 0xffff]++] = f[i];
			int[] d = f;
			f = to;
			to = d;
		}
		{
			int[] b = new int[65537];
			for (int i = 0; i < n; i++)
				b[1 + (f[i] >>> 16)]++;
			for (int i = 1; i <= 65536; i++)
				b[i] += b[i - 1];
			for (int i = 0; i < n; i++)
				to[b[f[i] >>> 16]++] = f[i];
			int[] d = f;
			f = to;
			to = d;
		}
		return f;
	}

	static void printArray(int ar[]) {
		System.out.println(Arrays.toString(ar));
	}

	static class Pair {
		int first, second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}

	}

	static class Pair2 {
		int first;
		Pair second;

		public Pair2(int first, Pair second) {
			this.first = first;
			this.second = second;
		}

	}

	static long expmodulo(long a, long b, long c) {
		long x = 1;
		long y = a;
		while (b > 0) {
			if (b % 2 == 1) {
				x = (x * y) % c;
			}
			y = (y * y) % c; // squaring the base
			b /= 2;
		}
		return (long) x % c;
	}

	// static int modInverse(int a, int m) {
	// int m0 = m;
	// int y = 0, x = 1;
	//
	// if (m == 1)
	// return 0;
	//
	// while (a > 1) {
	// int q = a / m;
	// int t = m;
	// m = a % m;
	// a = t;
	// t = y;
	// y = x - q * y;
	// x = t;
	// }
	// if (x < 0)
	// x += m0;
	// return x;
	// }

	static int gcd(int a, int b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);
	}

	static void sortMyMapusingValues(HashMap<Integer, Integer> hm) {

		List<Map.Entry<Integer, Integer>> capitalList = new LinkedList<>(hm.entrySet());

		Collections.sort(capitalList, new Comparator<Map.Entry<Integer, Integer>>() {
			public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
				return (o1.getValue()).compareTo(o2.getValue());
			}
		});
		HashMap<Integer, Integer> result = new HashMap<>();
		for (Map.Entry<Integer, Integer> entry : capitalList) {
			result.put(entry.getKey(), entry.getValue());
		}
	}

	static boolean ispowerof2(long num) {
		if ((num & (num - 1)) == 0)
			return true;
		return false;
	}

	static void primeFactors(int n) {
		while (n % 2 == 0) {
			System.out.print(2 + " ");
			n /= 2;
		}
		for (int i = 3; i <= Math.sqrt(n); i += 2) {
			while (n % i == 0) {
				System.out.print(i + " ");
				n /= i;
			}
		}
		if (n > 2)
			System.out.print(n);
	}

	static boolean isPrime(long n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		long sq = (long) Math.sqrt(n);
		for (int i = 5; i <= sq; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			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;
		}
	}

	static 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]);
			}
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

	}

	private static final FastReader fs = new FastReader();
	private static final OutputWriter op = new OutputWriter(System.out);
}