#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long nu[n];
  for (long long i = 0; i < n; ++i) {
    char a;
    cin >> a;
    nu[i] = a - '0';
  }
  long long f[10];
  for (long long i = 0; i < 9; ++i) cin >> f[i + 1];
  for (long long i = 0; i < n; ++i) {
    if (f[nu[i]] > nu[i]) {
      long long dab = i;
      for (dab = i; dab < n && f[nu[dab]] >= nu[dab]; ++dab) {
        nu[dab] = f[nu[dab]];
      }
      break;
    }
  }
  for (long long i = 0; i < n; ++i) {
    cout << nu[i];
  }
  cout << endl;
  return 0;
}
