#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e3 + 10;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  int a[10] = {0};
  bool ok = true;
  for (long long i = 1; i < 10; i++) cin >> a[i];
  for (long long i = 0; i < s.length(); i++) {
    int x = s[i] - '0';
    if (a[x] > x) {
      s[i] = '0' + a[x];
      ok = false;
      continue;
    }
    if (ok == false && a[x] < x) break;
  }
  cout << s;
  return 0;
}
