require 'ripper'

def calc(se)
	#p se
	case se[0]
	when :paren
		return nil if se[1][0][0] == :paren
		return nil if !se[1][0].flatten.include?(:binary)
		return calc(se[1][0])
	when :binary
		l, op, r = se[1..-1]
		return nil unless x = calc(l)
		return nil unless y = calc(r)
		result = x.send(op, y)
		return nil unless (0..1023) === result
		result
	when :@int
		r = se[1].to_i
		return (0..1023) === r ? r : nil
	when :unary
		if se[1] == :-@
			r = calc(se[2])
			return nil if !r
			return r == 0 ? 0 : nil
		elsif se[1] == :+@
			r = calc(se[2])
			return calc(se[2])
		else
			puts "unimplemented"
			return -1
		end
	else
		puts "unimplemented"
		return -1
	end
end

s = gets.chomp
s.gsub!(/\d+/){|b| b.to_i(2)}
k = s.count(?.)

if k == 0
	begin
		eval s
		r = calc(Ripper.sexp(s)[1][0])
		p (0..1023) === r ? r : -1
	rescue Exception
		p -1
	end
else
	p %w[ ( ) 0 1 + - * ].repeated_permutation(k).map {|perm|
		e = s.gsub(?.){ perm.pop }
		next -1 if e =~ /\*\*/
		#p e
		begin
			eval e
		rescue Exception
			next -1
		end
		calc(Ripper.sexp(e)[1][0]) || -1
	}.max
end