#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d[10] = {0};
  string s;
  cin >> n >> s >> d[1] >> d[2] >> d[3] >> d[4] >> d[5] >> d[6] >> d[7] >>
      d[8] >> d[9];
  for (int i = 0; i < n; ++i) {
    if (d[s[i] - '0'] > s[i] - '0') {
      s[i] = '0' + d[s[i] - '0'];
      for (int j = i + 1; j < n; ++j) {
        if (d[s[j] - '0'] < s[j] - '0') break;
        s[j] = '0' + d[s[j] - '0'];
      }
      break;
    }
  }
  cout << s << endl;
  return 0;
}
