#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, vis[11];
  string s;
  cin >> n >> s;
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= 9; i++) {
    cin >> t;
    if (t >= i) vis[i] = t;
  }
  for (int i = 0; i < n; i++) {
    if (vis[s[i] - '0'] && vis[s[i] - '0'] > s[i] - '0') {
      for (int j = i; j < n; j++)
        if (vis[s[j] - '0'])
          s[j] = vis[s[j] - '0'] + '0';
        else {
          cout << s;
          return 0;
        }
      break;
    }
  }
  cout << s;
  return 0;
}
