require 'ripper'

def parse(s)
	raise if s =~ /[-+*]{2,}/
	eval s
	Ripper.sexp(s)[1][0]
end

def calc(se)
	case se[0]
	when :paren
		raise if se[1][0][0] == :paren
		raise if !se[1][0].flatten.include?(:binary)
		calc(se[1][0])
	when :binary
		l, op, r = se[1..-1]
		result = calc(l).send(op, calc(r))
		raise unless (0..1023) === result
		result
	when :@int
		i = se[1].to_i(2)
		raise unless (0..1023) === i
		i
	when :unary
		if se[1] == :-@
			raise if calc(se[2]) == 0
			0
		elsif se[1] == :+@
			calc(se[2])
		end
	end
end

s = gets.chomp
k = s.count(?.)

if k == 0
	begin
		p calc(parse(s))
	rescue Exception
		p -1
	end
else
	 p %w[ ( ) 0 1 + - * ].repeated_permutation(k).map {|perm|
		e = s.gsub(?.){ perm.pop }
		begin
			calc(parse(e))
		rescue Exception
			next -1
		end
	}.max
end