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

solve(0,0).
solve(N,Sum) :-
  get_number(A),
  Next is N-1,
  solve(Next,S),
  Sum is S + A.

main :-
  get_number(A),
  get_number(N),
  solve(N,Sum),
  Ans is A - Sum,
  (Ans < 0 -> writeln(-1) ; writeln(Ans)).