#include <bits/stdc++.h>
using namespace std;
int v[200000];
int f[10];
int main() {
  int n;
  cin >> n;
  char c;
  for (int i = 0; i < n; i++) {
    cin >> c;
    v[i] = c - '0';
  }
  for (int i = 1; i < 10; i++) {
    cin >> f[i];
  }
  bool pornit = false;
  int i = 0;
  while (i < n && !pornit) {
    if (v[i] < f[v[i]]) {
      pornit = true;
      v[i] = f[v[i]];
      i++;
      while (i < n && v[i] <= f[v[i]]) {
        v[i] = f[v[i]];
        i++;
      }
    }
    i++;
  }
  for (int i = 0; i < n; i++) {
    cout << v[i];
  }
  return 0;
}
