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