#include <bits/stdc++.h>
using namespace std;
struct triplet {
  long long first, second, third;
};
int main() {
  long long n;
  int temp;
  map<int, int> m;
  string s, ans;
  int flag = 0;
  cin >> n >> s;
  for (long long i = 0; i < 9; i++) {
    cin >> temp;
    m[i + 1] = temp;
  }
  for (long long i = 0; i < n; i++) {
    int x = s[i] - '0';
    if (x < m[x] && flag != -1) {
      ans += (m[x] + '0');
      flag = 1;
    } else if (flag == 1 && x == m[x])
      ans += (m[x] + '0');
    else {
      if (flag == 1) flag = -1;
      ans += (x + '0');
    }
  }
  cout << ans << endl;
  return 0;
}
