#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int s[N], f[10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n, cnt = 0;
  char x;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    s[i] = x - '0';
  }
  for (int i = 1; i <= 9; ++i) cin >> f[i];
  bool flag = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] < f[s[i]]) {
      flag = 1;
      s[i] = f[s[i]];
    } else if (flag && s[i] > f[s[i]])
      break;
  }
  for (int i = 0; i < n; ++i) cout << s[i];
  return 0;
}
