#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  string a;
  cin >> a;
  map<int, int> ma;
  for (int i = 1; i <= 9; i++) {
    int e;
    cin >> e;
    ma[i] = e;
  }
  int t = 0;
  for (int i = 0; i < a.length(); i++) {
    if (ma[a[i] - '0'] > (a[i] - '0')) {
      t = i;
      break;
    }
  }
  for (int i = 0; i < t; i++) cout << a[i];
  for (int i = t; i < a.length(); i++) {
    if (ma[a[i] - '0'] >= (a[i] - '0')) {
      cout << ma[a[i] - '0'];
    } else {
      for (int c = i; c < a.length(); c++) cout << a[c];
      break;
    }
  }
}
