#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, w = -1;
  cin >> n;
  string s;
  cin >> s;
  long long a[9];
  for (int i = 0; i < 9; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    long long p = s[i] - 48;
    if (p < a[p - 1]) {
      w = i;
      break;
    }
  }
  if (w == -1) {
    cout << s;
    return 0;
  }
  for (long long i = w; i < n; i++) {
    long long p = s[i] - 48;
    if (p <= a[p - 1])
      s[i] = a[p - 1] + 48;
    else
      break;
  }
  cout << s;
  return 0;
}
