#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  string s;
  cin >> s;
  int A[11];
  for (int i = 1; i <= 9; i++) cin >> A[i];
  int st = -1, ed = n - 1;
  for (int i = 0; i < s.length(); i++) {
    int d = s[i] - '0';
    if (A[d] > d && st == -1) {
      st = i;
      continue;
    }
    if (A[d] < d and st != -1) {
      ed = i - 1;
      break;
    }
  }
  for (int i = st; i <= ed && st != -1; i++) {
    int d = s[i] - '0';
    char ch = A[d] + '0';
    s[i] = ch;
  }
  cout << s << endl;
  return 0;
}
