#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> M;
int main() {
  long long int n, i, j, k, x, y, t, m;
  cin >> n;
  string s;
  cin >> s;
  for (i = 1; i <= 9; i++) {
    cin >> x;
    M[i] = x;
  }
  for (i = 0; i < n; i++) {
    if (M[(long long int)s[i] - 48] > (long long int)s[i] - 48) {
      for (j = i; j < n; j++) {
        if (M[(long long int)s[j] - 48] < (long long int)s[j] - 48) {
          break;
        } else
          s[j] = (char)(M[(long long int)s[j] - 48] + 48);
      }
      cout << s << endl;
      return 0;
    }
  }
  cout << s << endl;
}
