program main
   integer :: x(3),t(3) = (/ 4, -9, 5 /)
   read(*, *)n,m
   i = n - m/1000
   dmax = i*2.d0/9.d0
   k = floor(dmax)
   x = (/-i, 2*i, m/1000/) + k*t
   if(any(x < 0)) x = -1
   write(*, *) x
end