#include <bits/stdc++.h>
using namespace std;
const int _1e5 = 100000;
const int _1e7 = 10000000;
const int _1e9 = 1000000000;
template <typename A, typename B>
ostream& operator<<(ostream& str, const pair<A, B>& p) {
  return str << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& str, const vector<T>& v) {
  str << "[";
  for (const auto& n : v) str << n << ", ";
  str << "]";
  return str;
}
template <typename T>
ostream& operator<<(ostream& str, const set<T>& v) {
  str << "{";
  for (const auto& n : v) {
    str << n << ", ";
  }
  str << "}";
  return str;
}
template <typename K, typename V>
ostream& operator<<(ostream& str, const unordered_map<K, V>& v) {
  str << "{";
  for (const auto& p : v) {
    str << p.first << " => " << p.second << ", ";
  }
  str << "}";
  return str;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.setf(std::ios::fixed);
  cout.precision(12);
  int n;
  cin >> n;
  string a;
  cin >> a;
  vector<int> f(10);
  f[0] = 0;
  for (int i = 1; i <= 9; ++i) {
    cin >> f[i];
  }
  int left_start = -1;
  for (int i = 0; i < a.size(); ++i) {
    int digit = a[i] - '0';
    if (f[digit] > digit) {
      left_start = i;
      break;
    }
  }
  if (left_start == -1) {
    cout << a << endl;
    return 0;
  }
  while (true) {
    if (left_start >= a.size()) {
      break;
    }
    int digit = a[left_start] - '0';
    if (f[digit] < digit) {
      break;
    }
    a[left_start++] = '0' + f[digit];
  }
  cout << a << endl;
}
