#!/usr/bin/perl

($startbit,$count) = @ARGV;

$status = ($startbit ? 0:4) x (1+log($count)/log(3));

for ( $i=0; $i < $count; $i++ ) {
        print $status++ =~ /[026]$/ ? 1:0;
        1 while $status =~ s/(\d)[37](\d*)$/$1+1 . ( ($1==1 || $1==5) ?
                        ("0" x (length($2)+1)) : (4 x (length($2)+1)) )/e;
        }

print "\n";
