#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int arr[10];
  string s;
  cin >> n >> s;
  for (int i = 1; i < 10; i++) cin >> arr[i];
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (flag && (s[i] - '0') > arr[s[i] - '0']) break;
    if ((s[i] - '0') < arr[s[i] - '0']) {
      s[i] = char(arr[s[i] - '0'] + '0');
      flag = 1;
    }
  }
  cout << s << endl;
  return 0;
}
