#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long f[10];
  for (int i = 1, ThxDem = 10; i < ThxDem; ++i) cin >> f[i];
  long long on = 0;
  for (int i = 0, ThxDem = ((int)s.size()); i < ThxDem; ++i) {
    if (!on) {
      if (f[0 + s[i] - '0'] > 0 + s[i] - '0') {
        on++;
        s[i] = (char)(f[0 + s[i] - '0'] + '0');
      }
    } else {
      if (f[0 + s[i] - '0'] >= 0 + s[i] - '0') {
        s[i] = (char)(f[0 + s[i] - '0'] + '0');
      } else {
        break;
      }
    }
  }
  cout << s;
  return 0;
}
