#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long a[11];
  for (long long i = 1; i <= 9; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    if (a[s[i] - '0'] > s[i] - '0') {
      while (i < n && a[s[i] - '0'] >= s[i] - '0') {
        s[i] = (char)('0' + a[s[i] - '0']);
        i++;
      }
      break;
    }
  }
  cout << s;
  return 0;
}
