get_string(String) :- current_input(Input),
  read_string(Input, ' \n', '', _, String).
     
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

fiz(N) :- K is N mod 3,K=\=0,A is N mod 5, A =\= 0.

solve(N,N,0).
solve(A,N,Sum) :- fiz(A),A1 is A+1,solve(A1,N,Sum1),Sum is Sum1+A.
solve(A,N,Sum) :- A1 is A+1,solve(A1,N,Sum).

main :- get_number(N),NN is N+1,solve(1,NN,S),writeln(S).


