#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   int main() {     fast();     long long n;     cin >> n;     char a[n + 10];     for (int i = 1; i <= n; ++i) cin >> a[i];     long long func[15];     for (int i = 1; i <= 9; ++i) {       cin >> func[i];     }     for (int i = 1; i <= n; ++i) {       if (func[a[i] -  0 ] > a[i] -  0 ) {         for (int j = i; j <= n; ++j) {           if (a[j] -  0  <= func[a[j] -  0 ])             a[j] = func[a[j] -  0 ] +  0 ;           else             break;         }         for (int j = 1; j <= n; ++j) cout << a[j];         return 0;       }     }     for (int i = 1; i <= n; ++i) cout << a[i];     return 0;   }   