#include <bits/stdc++.h>
using namespace std;
int main() {
  int d;
  cin >> d;
  string s;
  cin >> s;
  int m[10] = {};
  cin >> m[1] >> m[2] >> m[3] >> m[4] >> m[5] >> m[6] >> m[7] >> m[8] >> m[9];
  int i = 0;
  while (i < d) {
    int s2i = (int)s[i] - 48;
    if (m[s2i] > s2i) {
      break;
    }
    i++;
  }
  while (i < d) {
    int s2i = (int)s[i] - 48;
    if (m[s2i] < s2i) {
      break;
    }
    s[i] = (char)(m[s2i] + 48);
    i++;
  }
  cout << s << endl;
}
