#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  long long nt[200002], f[10], n, a = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c;
    nt[i] = (int)c - 48;
  }
  for (int i = 1; i <= 9; i++) {
    cin >> f[i];
  }
  for (int i = 1; i <= n; i++) {
    if ((f[nt[i]] == nt[i]) && (a == 0))
      cout << nt[i];
    else if (f[nt[i]] >= nt[i]) {
      if (a >= 0) {
        a++;
        cout << f[nt[i]];
      } else
        cout << nt[i];
    } else {
      if (a > 0) {
        a = -1;
        cout << nt[i];
      } else
        cout << nt[i];
    }
  }
  cout << endl;
}
