#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long power[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a[10];
  for (int i = 1; i < 10; i++) {
    cin >> a[i];
  }
  int flag = 0;
  for (int i = 0; i < s.length(); i++) {
    if (a[s[i] - 48] > (s[i] - 48)) {
      s[i] = (char)(a[s[i] - 48] + 48);
      flag = 1;
    } else if (flag && a[s[i] - 48] < (s[i] - 48)) {
      break;
    }
  }
  cout << s;
  return 0;
}
