#include <bits/stdc++.h>
int main() {
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  if (2 == 3) printf("---------------");
  int n;
  char s[200005];
  int t[200005];
  int mapp[9];
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    t[i] = s[i] - '0';
  }
  for (int i = 0; i < 9; i++) {
    scanf("%d", &mapp[i]);
  }
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (t[i] < mapp[t[i] - 1]) {
      t[i] = mapp[t[i] - 1];
      flag = 1;
    } else if (t[i] > mapp[t[i] - 1] && flag) {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d", t[i]);
  }
  printf("\n");
  return 0;
}
