#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, i, ans, flag = 0;
  map<char, char> mp;
  string st, st1;
  cin >> n >> st;
  for (i = '1'; i <= '9'; i++) {
    cin >> a;
    mp[i] = a + 48;
  }
  st1 = st;
  for (i = 0; i < st.size(); i++) {
    if (mp[st[i]] < st[i] && flag == 1) break;
    if (mp[st[i]] > st[i]) st1[i] = mp[st[i]], flag = 1;
  }
  cout << st1 << "\n";
  return 0;
}
