#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
void solve() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  map<char, char> m;
  for (int i = 1; i <= 9; i++) {
    int t;
    cin >> t;
    m[i + '0'] = t + '0';
  }
  bool flag = false;
  for (long long int i = 0; i < n; i++) {
    if (m[s[i]] > s[i]) {
      s[i] = m[s[i]];
      flag = true;
    } else if (m[s[i]] < s[i] && flag) {
      break;
    }
  }
  cout << s << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
