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