program main
  implicit none
  integer :: A(5),ind(5)
  integer :: i
  integer :: i1,i2,i3,i4,i5
  integer :: tmin,tmp
  do i = 1,5
     read(*,*) A(i)
  end do
  tmin = sum(A) + 60
  do i1 = 1,5
     do i2 = 1,5
        if ( i2 == i1 ) cycle
        do i3 = 1,5
           if ( i3 == i2 .or. i3 == i1 ) cycle
           do i4= 1,5
              if ( i4 == i3 .or. i4 == i2 .or. i4 == i1 ) cycle
              do i5= 1,5
                 if ( i5 == i4 .or. i5 == i3 .or. i5 == i2 .or. i5 == i1 ) cycle
                 ind=(/i1,i2,i3,i4,i5/)
                 call tmesure(tmp,ind)
                 if (tmp < tmin) tmin = tmp
              end do
           end do
        end do
     end do
  end do
  write(*,'(i0)') tmin
  stop
contains

  subroutine tmesure(t,ind)
    integer,intent(out) :: t
    integer,intent(in) :: ind(5)
    t=0
    do i = 1,5
       if ( mod(t,10) /=0 ) t = t+10-mod(t,10)
       t = t+A(ind(i))
    end do
  end subroutine tmesure
end program main
