import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N=sc.nextInt(); int bign=-1; int lc=-1; String K = sc.next(); int[] Cjust=new int[9]; for(var i=0;i<9;i++){ Cjust[i]=sc.nextInt(); } int[] Cbig=new int[9]; for (int i=0;i<9;i++){ Cbig[i]=Cjust[i]; } sc.close(); if(N<(int)K.length()){ System.out.println(-1); } else if(N>(int)K.length()){ StringBuilder sb = new StringBuilder(); for(int i=0;i<9;i++){ for(int num=Cjust[i];num>0;num--){ sb.append((char)(i+'1')); } } System.out.println(sb); } else{ for (int i=0;i0){ for(int d=Math.max(bign,0);d0){ Cjust[K.charAt(i)-'1']--; } else break; } if(bign==-1){ System.out.println(-1); } else{ StringBuilder sb = new StringBuilder(); sb.append(K.substring(0,bign)).append((char)(lc+'1')); Cbig[lc]--; for(int j=0;j<9;j++){ for(int k=0;k