#include <bits/stdc++.h>
using namespace std;
int f[20];
bool ischange[300000];
int main() {
  memset(ischange, 0, sizeof ischange);
  int n;
  scanf("%d", &n);
  string a;
  cin >> a;
  for (int i = 1; i <= 9; i++) {
    scanf("%d", &f[i]);
  }
  int ff = 0;
  for (int i = 0; i < a.length(); i++) {
    if (ff == 1) break;
    int now = a[i] - '0';
    int change = f[now];
    if (change > now) {
      ff = 1;
      while (f[a[i] - '0'] >= a[i] - '0' && i < a.length()) {
        ischange[i] = 1;
        i++;
      }
    }
    if (ff == 1) break;
  }
  for (int i = 0; i < a.length(); i++) {
    if (ischange[i])
      cout << f[a[i] - '0'];
    else
      cout << a[i];
  }
  return 0;
}
