#include <bits/stdc++.h>
const double eps = 1e-8;
using namespace std;
inline long long read() {
  char ch = getchar();
  long long s = 0, w = 1;
  while (ch < 48 || ch > 57) {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= 48 && ch <= 57) {
    s = (s << 1) + (s << 3) + (ch ^ 48);
    ch = getchar();
  }
  return s * w;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
long long n, a[200005], f[10], flag[10];
string s;
int main() {
  n = read();
  cin >> s;
  for (register long long i = 0; s[i]; i++) {
    a[i + 1] = s[i] - 48;
  }
  for (register long long i = 1; i <= 9; i++) f[i] = read();
  for (register long long i = 1; i <= n; i++) {
    if (a[i] < f[a[i]]) {
      while (a[i] <= f[a[i]] && i <= n) {
        a[i] = f[a[i]];
        i++;
      }
      for (register long long i = 1; i <= n; i++) {
        cout << a[i];
      }
      return 0;
    }
  }
  for (register long long i = 1; a[i]; i++) {
    cout << a[i];
  }
  return 0;
}
