#include <bits/stdc++.h>
using namespace std;
const int Max = 2e5 + 5;
int n;
char f[10];
string a;
bool flag = 0;
int main() {
  cin >> n;
  cin >> a;
  for (int i = 1; i <= 9; ++i) cin >> f[i];
  for (int i = 0; i < n; ++i) {
    if (f[a[i] - '0'] > a[i]) {
      flag = 1;
      a[i] = f[a[i] - '0'];
    } else if (f[a[i] - '0'] < a[i])
      if (flag) break;
  }
  cout << a << endl;
  return 0;
}
