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