def deser_unary(ser):
    """
    unary_zero$0 = Unary ~0;
    unary_succ$1 {n:#} x:(Unary ~n) = Unary ~(n + 1);
  """
    n = 0
    while True:
        r = ser.pop(0)
        if r:
            n += 1
        else:
            return n, ser
