program abc162a
   implicit none
   integer(8) :: N, i
   integer(8), allocatable :: array(:)

   read(*,*) N
   allocate(array(N))

   do i = 1, N
      array(i) = i
   end do

   do i = 1, N
      if (mod(array(i),3) == 0 .or. mod(array(i), 5) == 0) then
         array(i) = 0
      endif
   end do

   write(*,*) sum(array(:))


end program abc162a
