#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int arr[10];
  arr[0] = 0;
  for (int i = 1; i < 10; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    if ((int)arr[s[i] - '0'] <= (int)(s[i] - '0')) continue;
    for (int j = i; j < n; j++) {
      if ((int)arr[s[j] - '0'] >= (int)(s[j] - '0')) {
        s[j] = (char)(arr[s[j] - '0'] + '0');
      } else {
        break;
      }
    }
    break;
  }
  cout << s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
