#include <bits/stdc++.h>
const double PI =
    3.141592653589793238462643383279502884197169399375105820974944;
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long arr[10];
  for (long long i = 1; i < 10; ++i) {
    cin >> arr[i];
  }
  string mx = s;
  long long inc = 0;
  string temp = s;
  for (long long i = 0; i < n; ++i) {
    if (arr[s[i] - '0'] >= s[i] - '0') {
      temp[i] = (char)(arr[s[i] - '0'] + '0');
      ++inc;
    } else {
      mx = max(mx, temp);
      inc = 0;
      temp = s;
    }
  }
  mx = max(mx, temp);
  cout << mx << "\n";
}
int32_t main() {
  bool testing = false;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (testing) {
    freopen("test1.txt", "rt", stdin);
    long long start = clock();
    solve();
    long long end = clock();
    cout << "time: " << (end - start) / (double)(CLOCKS_PER_SEC)*1000
         << " milliseconds\n";
  } else {
    solve();
  }
}
