#include <bits/stdc++.h>
using namespace std;
bool prime[100001];
bool ispoweroftwo(long long int x) { return x && !(x & (x - 1)); }
long long int xorcal(long long int n) {
  if (n % 4 == 0) return n;
  if (n % 4 == 1) return 1;
  if (n % 4 == 2) return n + 1;
  if (n % 4 == 3) return 0;
}
void sieve(long long int n) {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (long long int i = 2; i * i <= n; i++) {
    if (prime[i] == true) {
      for (long long int j = i * i; j <= n; j += i) {
        prime[j] = false;
      }
    }
  }
}
bool isprime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 or n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i += 6) {
    if (n % i == 0 or n % (i + 2) == 0) return false;
  }
  return true;
}
long long int modinverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m;
    a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return (b % a, a);
}
long long int power(long long int A, long long int B) {
  if (A == 0) return 0;
  if (B == 0) return 1;
  long long int y;
  if (B % 2 == 0) {
    y = power(A, B / 2);
    y = (y * y) % 1000000007;
  } else {
    y = A % 1000000007;
    y = (y * power(A, B - 1) % 1000000007) % 1000000007;
  }
  return (long long int)((y + 1000000007) % 1000000007);
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  char f[10];
  for (long long int i = 1; i < 10; i++) {
    cin >> f[i];
  }
  long long int fl = 0;
  for (long long int i = 0; i < n; i++) {
    if (s[i] < f[s[i] - '0']) {
      s[i] = f[s[i] - '0'];
      fl = 1;
    } else if (fl == 1 and s[i] > f[s[i] - '0']) {
      break;
    }
  }
  cout << s << '\n';
  return 0;
}
