#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
char s[maxn];
int vis[maxn];
int main() {
  int n;
  cin >> n >> s + 1;
  for (int i = 1; i <= 9; i++) cin >> vis[i];
  for (int i = 1; i <= n; i++) s[i] -= '0';
  for (int i = 1; i <= n; i++)
    if (s[i] < vis[s[i]]) {
      int j = i;
      while (j <= n) {
        if (s[j] <= vis[s[j]])
          s[j] = vis[s[j]];
        else
          break;
        j++;
      }
      break;
    }
  for (int i = 1; i <= n; i++) printf("%d", s[i]);
}
