#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, g[15];
  string num;
  cin >> n >> num;
  for (int i = 1; i <= 9; i++) {
    cin >> g[i];
  }
  bool beg = false;
  for (int i = 0; i < num.size(); i++) {
    if (!beg && (num[i] - '0') < g[(num[i] - '0')]) {
      beg = true;
      num[i] = g[(num[i] - '0')] + '0';
    } else if (beg && (num[i] - '0') <= g[(num[i] - '0')]) {
      num[i] = g[(num[i] - '0')] + '0';
    } else if (beg) {
      break;
    }
  }
  cout << num;
  return 0;
}
