import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    }
    static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    }
    static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    }
} Main public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] a = new int[5]; a new int[5] 5 int ans = 1000000000; ans 1000000000 for(int i=0;i<5;i++) a[i]= sc.nextInt(); int i=0; int i=0; i 0 i<5 i 5 i++ i++ i a[i]= sc.nextInt(); a[i]= sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        } int s=12345; int s=12345; s 12345 s<=54321 s 54321 s++ s++ s {
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        } {
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        } char[] cur = Integer.toString(s).toCharArray(); cur Integer.toString(s).toCharArray() Integer.toString(s).toCharArray Integer.toString(s) Integer.toString Integer s if(!legal(cur)) continue; !legal(cur) legal(cur) legal cur continue; int time = 0; time 0 for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            } int i=0; int i=0; i 0 i<5 i 5 i++ i++ i {
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            } {
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            } if(time%10!=0) time = (time/10+1)*10; time%10!=0 time%10 time 10 0 time = (time/10+1)*10 time (time/10+1)*10 (time/10+1) time/10 time 10 1 10 time += a[cur[i]-'1'] time a[cur[i]-'1'] a cur[i]-'1' cur[i] cur i '1' ans = Math.min(ans,time) ans Math.min(ans,time) Math.min Math ans time System.out.println(ans) System.out.println System.out System System.out ans String[] args args static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    } legal {
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    } int[] rec = new int[10]; rec new int[10] 10 for(char w:s) rec[w-'0']++; char w s rec[w-'0']++; rec[w-'0']++ rec[w-'0'] rec w-'0' w '0' boolean ans = true; ans true for(int i=1;i<=5;i++) ans &= rec[i]==1; int i=1; int i=1; i 1 i<=5 i 5 i++ i++ i ans &= rec[i]==1; ans &= rec[i]==1 ans rec[i]==1 rec[i] rec i 1 return ans; ans char[] s s public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    }
    static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    }
} public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    }
    static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //PrintWriter out = new PrintWriter(System.out);
        int[] a = new int[5];
        int ans = 1000000000;
        for(int i=0;i<5;i++) a[i]= sc.nextInt();
        for(int s=12345;s<=54321;s++){
            char[] cur = Integer.toString(s).toCharArray();
            if(!legal(cur)) continue;
            int time = 0;
            for(int i=0;i<5;i++){
                if(time%10!=0) time = (time/10+1)*10;
                time += a[cur[i]-'1'];
            }
            ans = Math.min(ans,time);
        }
        System.out.println(ans);
    }
    static boolean legal(char[] s){
        int[] rec = new int[10];
        for(char w:s) rec[w-'0']++;
        boolean ans = true;
        for(int i=1;i<=5;i++) ans &= rec[i]==1;
        return ans;
    }
}