#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  char arr[10];
  for (int i = 1; i <= 9; i++) cin >> arr[i];
  int f = 0, f1 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (arr[s[i] - '0'] == s[i] && f1 == 1) {
    } else if (arr[s[i] - '0'] > s[i] && f == 0) {
      s[i] = arr[s[i] - '0'];
      f1 = 1;
    } else if (f1 == 1)
      f = 1;
  }
  cout << s;
}
