#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 2;
const int mov[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
const int Mov[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
  return;
}
int main(void) {
  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  std::vector<char> m(10);
  for (int i = 1; i <= 9; i++) {
    cin >> m[i];
  }
  int i = 0;
  while (s[i] >= m[s[i] - '0']) i++;
  while (s[i] <= m[s[i] - '0'] && i < n) s[i] = m[s[i] - '0'], i++;
  cout << s << endl;
}
