#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tests = 1;
  while (tests--) {
    string s;
    long long n;
    cin >> n >> s;
    vector<long long> v(10);
    for (long long i = 1; i < 10; i++) cin >> v[i];
    long long i = 0;
    while (i < n && s[i] - '0' >= v[s[i] - '0']) i++;
    while (i < n && s[i] - '0' <= v[s[i] - '0']) {
      s[i] = v[s[i] - '0'] + '0';
      i++;
    }
    cout << s;
  }
  return 0;
}
