#include <bits/stdc++.h>
const int MAXN = 3e5 + 5;
using namespace std;
string s, ans = "";
int n, i, use = 0;
char mapp[10];
int main() {
  cin >> n;
  cin >> s;
  for (i = 1; i <= 9; i++) {
    cin >> mapp[i];
  }
  for (i = 0; i < n; i++) {
    if (s[i] >= mapp[s[i] - '0']) {
      ans += s[i];
    } else {
      while (i < n && mapp[s[i] - '0'] >= s[i]) {
        ans += mapp[s[i] - '0'];
        i += 1;
      }
      break;
    }
  }
  for (; i < n; i++) ans += s[i];
  cout << ans << endl;
}
