#include <bits/stdc++.h>
using namespace std;
constexpr long long int INF = 4294967297;
constexpr double pi = 3.14159265358979;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  string s;
  cin >> n >> s;
  vector<char> f;
  for (char x; cin >> x;) {
    f.push_back(x);
  }
  bool was = 0;
  for (long long int i = 0; i < n; ++i) {
    char x = s[i], y = f[x - 49];
    if (y < x) {
      if (was)
        return cout << s, 0;
      else
        continue;
    } else {
      if (x == y && !was) continue;
      was = 1;
      s[i] = f[s[i] - 49];
    }
  }
  cout << s;
  return 0;
}
