   program abc162b
      implicit none
      integer::n,i
      integer(8)::sum0

         read *,n

         sum0=0
         do i=1,n
            if (mod(i,3)/=0) then
               if (mod(i,5)/=0) then
                  sum0=sum0+i
               end if
            end if
         end do

         print *,sum0

   end program abc162b