#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  unordered_map<char, char> um;
  for (int i = 1; i < 10; i++) {
    int tmp;
    cin >> tmp;
    um[i + '0'] = tmp + '0';
  }
  int i = 0;
  while (i < n) {
    if (s[i] < um[s[i]]) {
      while (i < n && s[i] <= um[s[i]]) {
        s[i] = um[s[i]];
        i++;
      }
      break;
    } else {
      i++;
    }
  }
  cout << s << endl;
  return 0;
}
