#include <bits/stdc++.h>
using namespace std;
string s;
bool check;
long long x[10], n;
int main() {
  cin >> n;
  cin >> s;
  for (int i = 1; i <= 9; i++) cin >> x[i];
  for (int i = 0; i < n; i++) {
    long long X = s[i] - '0';
    if (X < x[X]) {
      check = true;
      s[i] = x[X] + '0';
    } else if (X > x[X]) {
      if (check)
        break;
      else
        continue;
    }
  }
  cout << s;
}
