#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 5;
int a[maxn];
int n;
string s;
int main() {
  while (cin >> n) {
    s.clear();
    memset(a, 0, sizeof(a));
    cin >> s;
    for (int i = 1; i <= 9; i++) {
      cin >> a[i];
    }
    int pos = 0;
    for (int i = 0; i < n; i++) {
      int tmp = s[i] - '0';
      if (tmp < a[tmp]) {
        s[i] = a[tmp] + '0';
        pos = i;
        break;
      }
    }
    for (int i = pos + 1; i < n; i++) {
      int tmp = s[i] - '0';
      if (tmp > a[tmp]) break;
      if (tmp < a[tmp]) {
        s[i] = a[tmp] + '0';
        pos = i;
      }
    }
    cout << s << endl;
  }
  return 0;
}
