#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2000;
const long long Mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
vector<pair<int, int> > a[N];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  map<int, int> mp;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    a[i] = s[i] - '0';
  }
  for (int i = 0; i < 9; i++) {
    int x;
    cin >> x;
    mp[i + 1] = x;
  }
  int t = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (mp[a[i]] > a[i] && t == 0) {
      cout << mp[a[i]];
      flag = 1;
    } else if (mp[a[i]] == a[i]) {
      cout << a[i];
    } else {
      cout << a[i];
      if (flag) t = 1;
    }
  }
  return 0;
}
