#include <bits/stdc++.h>
using namespace std;
long long prime[10000001] = {0};
int GCD(int A, int B) {
  int m = min(A, B), gcd;
  for (int i = m; i > 0; --i)
    if (A % i == 0 && B % i == 0) {
      gcd = i;
      return gcd;
    }
}
long long count_one(long long n) {
  long long count1 = 0;
  while (n) {
    n = n & (n - 1);
    count1++;
  }
  return count1;
}
std::vector<pair<long long, long long> > q;
std::vector<long long> v, v1;
long long n, k, count1 = 0, h, mx = -1, mn = 1000000000000000000;
int a[200005] = {0};
int an[5][5];
long long fx[7] = {1, 2, 3, 1, 3, 2, 1};
long long ans[100][100];
unordered_map<long long, long long> m;
int main() {
  cin >> n;
  string s;
  cin >> s;
  v.push_back(0);
  for (long long i = 0; i < 9; i++) {
    long long x;
    cin >> x;
    v.push_back(x);
  }
  for (long long i = 0; i < n; i++) {
    long long x = s[i] - '0';
    if (v[x] > x) {
      while (x <= v[x] && i < n) {
        s[i] = v[x] + '0';
        count1++;
        i++;
        x = s[i] - '0';
      }
      break;
    }
  }
  std::cout << s << '\n';
}
