program base_2Number
    implicit none
    integer(8):: n, ia, i, sgn=1
    character(1), allocatable:: ans(:)
 
    read*, n
    if (n==0) then
        print*, 0
    end if
    allocate(ans(1))
    ia=0
    do while(abs(n) >= 1)
        ia=ia+1
        call append(ia,mod(n,2))
        n = (n-abs(mod(n,2))*sgn) / 2
        sgn=-1*sgn
    end do
 
    print*, ans(ia:1:-1)
 
    contains
    subroutine append(i, num)
        integer(8):: i, num
        character(1), allocatable:: tmp(:)
 
        if (i > size(ans)) then
            allocate(tmp(size(ans)))
            tmp(:) = ans(:)
            deallocate(ans)
            allocate(ans(size(tmp)*2))
            ans(1:size(tmp)) = tmp(:)
        end if
        ans(i) = char(abs(num)+ichar('1')-1)
    end subroutine
end program base_2Number