#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string num;
  int arr[9];
  cin >> n;
  cin >> num;
  int start = -1, end = -1;
  for (int i = 0; i < 9; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    if ((num[i] - '0') < arr[num[i] - '1']) {
      start = i;
      break;
    }
  }
  if (start != -1) {
    int s = start;
    while (true) {
      if (num[s] - '0' > arr[num[s] - '1']) break;
      num[s] = arr[num[s] - '1'] + '0';
      s++;
      if (s == n) break;
    }
  }
  cout << num << endl;
  return 0;
}
