#include <bits/stdc++.h>
using namespace std;
int visit[20];
char s[200500];
int a[200500], b[200500];
int main() {
  int n, flag;
  while (cin >> n) {
    cin >> s;
    flag = 0;
    for (int i = 0; i < n; i++) a[i] = s[i] - '0', b[i] = a[i];
    for (int i = 1; i <= 9; i++) cin >> visit[i];
    for (int i = 0; i < n; i++) {
      if (flag == 0) {
        if (s[i] - '0' < visit[s[i] - '0']) {
          flag = 1;
          b[i] = visit[s[i] - '0'];
        }
      } else {
        if (s[i] - '0' > visit[s[i] - '0'])
          break;
        else {
          b[i] = visit[s[i] - '0'];
        }
      }
    }
    for (int i = 0; i < n; i++) cout << b[i];
    cout << endl;
  }
}
