#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string a;
  cin >> a;
  map<char, char> f;
  for (int i = '1'; i <= '9'; i++) cin >> f[i];
  int i = 0;
  while (a[i] >= f[a[i]] && i < n) ++i;
  while (a[i] <= f[a[i]] && i < n) a[i] = f[a[i]], ++i;
  cout << a << endl;
}
