a(n, base = 2) = {
	my (d = digits(n, base), w = #d);
	for (i = 1, oo,
		if (w+i-1 > #d,
			d = concat(d, d);
		);
		my (s = Set(vector(w, j, fromdigits(d[j..j+i-1], base))));
		for (v = base^(i-1), base^i-1,
			if (!setsearch(s, v),
				return (v-1);
			);
		);
	);
}

for (n = 1, 2^13, print (n " " a(n)))

quit