get(Number) :-
 current_input(Input),
 read_string(Input, "\n", "", _, String),
 number_string(Number,String).

solve(0,0).
solve(N,S) :-
 M is N-1, solve(M,T), U is (N mod 3)*(N mod 5),
 (U=0 -> A=0 ; A=N), S=A+T.

main :-
 get(N),solve(N,S),T is S,writeln(T).