#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int f[12];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  string s;
  cin >> n;
  cin >> s;
  for (int i = 1; i < 10; ++i) {
    cin >> f[i];
  }
  for (int i = 0; i < n; ++i) {
    if (f[s[i] - '0'] > s[i] - '0') {
      for (int j = i; j < n; ++j) {
        if (f[s[j] - '0'] < s[j] - '0') {
          break;
        }
        s[j] = f[s[j] - '0'] + '0';
      }
      break;
    }
  }
  cout << s << "\n";
  return 0;
}
