#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
map<int, int>::iterator it;
long long int n, i, x, y, z, j, len, cnt = 0, sum = 0, a, b, c, temp, d,
                                     res = 0, k, tc, mod = 1000003, t, r, pos,
                                     ans = 0, m, q, mx;
int arr[2 * 100005], ar[15];
int dp[1000];
long long int two[1000][1000];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
string str, st;
queue<int> que;
vector<int> vec;
char ch;
int Bigmod(long long int a, long long int b, long long int c) {
  long long int x;
  if (b == 0) return 1 % c;
  x = Bigmod(a, b / 2, c);
  x = (x * x) % c;
  if (b % 2) {
    x = (x * x * a) % c;
  }
  return x;
}
int start;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cerr.tie(NULL);
  cin >> n;
  cin >> str;
  for (i = 1; i <= 9; i++) cin >> ar[i];
  for (int i = 0; i < n; i++) arr[i + 1] = (str[i] - '0');
  for (i = 1; i <= n; i++) {
    if (arr[i] < ar[arr[i]]) break;
  }
  for (; i <= n; i++) {
    if (arr[i] > ar[arr[i]])
      break;
    else
      arr[i] = ar[arr[i]];
  }
  for (i = 1; i <= n; i++) cout << arr[i];
  return 0;
}
