#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int maxn = 2e5 + 5;
int n;
char s[maxn];
int f[15];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= 9; i++) scanf("%d", &f[i]);
  bool start = false;
  for (int i = 1; s[i]; i++) {
    int a = s[i] - '0';
    if (f[a] > a) {
      s[i] += f[a] - a;
      start = true;
    } else if (f[a] < a) {
      if (start) break;
    }
  }
  puts(s + 1);
  return 0;
}
