import java.util.Scanner;

public class Main {
	private static int min=100000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	}

	public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	private static int min=100000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	}

	public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	}
} Main private static int min=100000000; min 100000000 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	} main {
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] p=new int[5]; p new int[5] 5 p[0]=sc.nextInt() p[0] p 0 sc.nextInt() sc.nextInt sc p[1]=sc.nextInt() p[1] p 1 sc.nextInt() sc.nextInt sc p[2]=sc.nextInt() p[2] p 2 sc.nextInt() sc.nextInt sc p[3]=sc.nextInt() p[3] p 3 sc.nextInt() sc.nextInt sc p[4]=sc.nextInt() p[4] p 4 sc.nextInt() sc.nextInt sc sc.close() sc.close sc String key="01234"; key "01234" permutation(key,"",p) permutation key "" p System.out.println(min) System.out.println System.out System System.out min String[] args args public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	} permutation {
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	} if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		} q.length() <= 1 q.length() q.length q 1 {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} char[] ch=(ans+q).toCharArray(); ch (ans+q).toCharArray() (ans+q).toCharArray (ans+q) ans q int val=0; val 0 for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			} int i=0; int i=0; i 0 i<ch.length i ch.length ch ch.length i++ i++ i {
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			} {
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			} int mod=val%10; mod val%10 val 10 if(mod!=0)val +=(10-mod); mod!=0 mod 0 val +=(10-mod) val (10-mod) 10 mod int v=Character.getNumericValue(ch[i]); v Character.getNumericValue(ch[i]) Character.getNumericValue Character ch[i] ch i val +=p[v] val p[v] p v min=Math.min(min, val) min Math.min(min, val) Math.min Math min val {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		} for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			} int i = 0; int i = 0; i 0 i < q.length() i q.length() q.length q i++ i++ i {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			} {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			} permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p) permutation q.substring(0, i) + q.substring(i + 1) q.substring(0, i) q.substring q 0 i q.substring(i + 1) q.substring q i + 1 i 1 ans + q.charAt(i) ans q.charAt(i) q.charAt q i p String q q String ans ans int[] p p public class Main {
	private static int min=100000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	}

	public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	}
} public class Main {
	private static int min=100000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	}

	public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {
	private static int min=100000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] p=new int[5];
		p[0]=sc.nextInt();
		p[1]=sc.nextInt();
		p[2]=sc.nextInt();
		p[3]=sc.nextInt();
		p[4]=sc.nextInt();
		sc.close();
		String key="01234";
		permutation(key,"",p);
		System.out.println(min);
	}

	public static void permutation(String q, String ans,int[] p){
		if(q.length() <= 1) {
			char[] ch=(ans+q).toCharArray();
			int val=0;
			for(int i=0;i<ch.length;i++){
        		int mod=val%10;
        		if(mod!=0)val +=(10-mod);
				int v=Character.getNumericValue(ch[i]);
        		val +=p[v];
			}
			min=Math.min(min, val);
		} else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),ans + q.charAt(i),p);
			}
		}
	}
}