#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  int gg[10];
  for (int i = 1; i <= 9; i++) cin >> gg[i];
  bool doed = false, dd = false;
  for (int i = 0; i < n; i++)
    if (str[i] - '0' < gg[str[i] - '0'] && !dd)
      str[i] = gg[str[i] - '0'] + '0', doed = true;
    else if (str[i] - '0' > gg[str[i] - '0'] && doed)
      dd = true;
  cout << str;
}
