const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var A = [intShift(),intShift(),intShift(),intShift(),intShift()];
  var o = [];
  for(var i = 0 ; i < 3125 ; i++){
  	var a = i.toString(5);
    while(a.length!=5)a="0"+a;
    if(a.indexOf("0")==-1)continue;
    if(a.indexOf("1")==-1)continue;
    if(a.indexOf("2")==-1)continue;
    if(a.indexOf("3")==-1)continue;
    if(a.indexOf("4")==-1)continue;
    a = a.split(NOSP).map(a=>~~a);
    var sum = 0;
    for(var j = 0; j < 5; j++){
    	sum += A[a[j]];
    	if(sum % 10 && j < 4)sum = sum + 10 - (sum % 10);
    }
    o.push(sum);
  }
  return ~~Math.min(...o);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
123
123
123
123
123
`);