#include <bits/stdc++.h>
using namespace std;
long long fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long ar[5000005], br[500005];
vector<long long> a, b, c;
map<long long, long long> m1, m2, m3;
void Execute() {
  long long N, NB, VAL, A, B, C, G, INC, DEC, L, R, D;
  cin >> N;
  string sr, srr = "";
  cin >> sr;
  for (long long i = (1); i <= (9); i++) cin >> ar[i];
  bool ore_mama = true;
  for (long long i = (0); i <= (N - 1); i++) {
    long long cs = sr[i] - '0';
    if (ar[cs] > cs) {
      char f = ar[cs] + '0';
      sr[i] = f;
      ore_mama = false;
    } else {
      if (ore_mama == false && ar[cs] < cs) break;
    }
  }
  cout << (sr) << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  Execute();
}
