#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (cin >> n) {
    long long a[15];
    string s;
    vector<long long> s1;
    cin >> s;
    for (long long i = 0; i < 9; i++) {
      cin >> a[i];
    }
    long long position = -1;
    long long flag = 0;
    for (long long i = 0; i < s.size(); i++) {
      if ((s[i] - '0') >= a[(s[i] - '0') - 1] && flag == 0) {
        s1.push_back((s[i]) - '0');
      } else if ((s[i] - '0') <= a[(s[i] - '0') - 1]) {
        flag = 1;
        s1.push_back(a[s[i] - '0' - 1]);
      } else {
        position = i;
        break;
      }
    }
    if (position != -1) {
      for (long long i = position; i < s.size(); i++) {
        s1.push_back((s[i]) - '0');
      }
    }
    for (long long i = 0; i < s1.size(); i++) {
      cout << s1[i];
    }
    cout << endl;
  }
}
