require 'ripper'

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

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

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