program fizzbuzz_sum
  implicit none
  integer(8) :: n, i, s = 0_8
  read(*,*) n
  do i = 1_8, n
    if (mod(i,3_8)*mod(i,5_8) == 0_8) cycle
    s = s+i
  end do
  write(*,'(i0)') s
end program fizzbuzz_sum