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

get_number(Number) :-
  get_string(String),
  number_string(Number, String).

fb(0, 0).
fb(N, S) :-
  N1 is N - 1,
  fb(N1, S1),
  ((N mod 3 =:= 0; N mod 5 =:= 0) ->
    S is S1;
    S is S1 + N).

main :-
  get_number(N),
  fb(N, S),
  write(S).