#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const long long M = 1e6 + 5;
const long long mod = 1e9 + 7;
const long long m1 = 1e9 + 7;
const long long m2 = 1e9 + 9;
const long long p1 = 402653189;
const long long p2 = 1610612741;
const long long LN = 21;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
  return (max(a, b) / gcd(a, b)) * min(a, b);
}
long long dx[4] = {-1, 1, 0, 0};
long long dy[4] = {0, 0, 1, -1};
long long pw[LN], fact[N], invfact[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i, j;
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long mp[10];
  for (i = 1; i <= 9; i++) cin >> mp[i];
  for (i = 0; i < n; i++) {
    long long val = s[i] - '0';
    if (mp[val] > val) {
      for (j = i; j < n; j++) {
        if (mp[s[j] - '0'] < s[j] - '0') break;
        s[j] = '0' + mp[s[j] - '0'];
      }
      break;
    }
  }
  cout << s;
  return 0;
}
