#include <bits/stdc++.h>
using namespace std;
char a[200010];
int main() {
  int n;
  vector<int> s;
  int f[10];
  cin >> n;
  cin >> a;
  for (int i = 1; i <= 9; i++) cin >> f[i];
  for (int i = 0; i < n; i++) s.push_back(f[a[i] - '0'] - (a[i] - '0'));
  for (int i = 0; i < n; i++) {
    if (s[i] > 0) {
      while (i < n && s[i] >= 0) {
        a[i] = char(f[a[i] - '0'] + '0');
        i++;
      }
      break;
    }
  }
  cout << a << endl;
  return 0;
}
