import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._
  val str = readLine.trim
  val count = str.count(_ == '.')
  if (count == 0) {
    str match{
      case Expression(e) ⇒ println(e)
      case _ ⇒ println(-1)
    }
  }else {
    println((0 until count).foldLeft(List(str)){case (l, _) ⇒ List("0","1","+","-","*","(",")").flatMap{c ⇒ l.map{_.replaceFirst("\\.", c)}}}.collect{
      case Expression(e) ⇒ e
    } match {
      case e if e.nonEmpty ⇒ e.max
      case _ ⇒ -1
    })
  }
}
object Expression {
  def unapply(arg: String): Option[Int] = {
    arg.toList match {
      case f Formula Nil ⇒ f.value
      case _ ⇒ None
    }
  }
  object Number {
    def unapply(arg: List[Char]): Option[(Term, List[Char])] = {
      arg.span(_.isDigit) match {
        case (Nil, _) ⇒ None
        case (n, rest) ⇒ Some(new Number(n.foldLeft(0){case (acc, d) ⇒ acc * 2 + d.asDigit}), rest)
      }
    }
  }
  object Factor{
    def unapply(arg: List[Char]): Option[(Term, List[Char])] = {
      arg match {
        case n Number rest ⇒ Some(n, rest)
        case '('::(t Formula ')'::r) if t.count > 1 ⇒ Some(Bracket(t), r)
        case _ ⇒ None
      }
    }
  }
  object Formula {
    def unapply(arg: List[Char]): Option[(Term, List[Char])] = {
      arg match {
        case left Term rest ⇒ Some(takeAll(rest, left))
        case _ ⇒ None
      }
    }
    @tailrec private[this] def takeAll(arg: List[Char], left: Term): (Term, List[Char]) = {
      arg match {
        case '+'::(right Term rest) ⇒ takeAll(rest, new Add(left, right))
        case '-'::(right Term rest) ⇒ takeAll(rest, new Sub(left, right))
        case _ ⇒ (left, arg)
      }
    }
  }
  object Term {
    def unapply(arg: List[Char]): Option[(Term, List[Char])] = {
      arg match {
        case f Factor rest ⇒ Some(takeAll(rest, f))
        case _ ⇒ None
      }
    }
    @tailrec private[this] def takeAll(arg: List[Char], left: Term): (Term, List[Char]) = {
      arg match {
        case '*'::(right Factor rest) ⇒ takeAll(rest, new HighPriority(left, right))
        case _ ⇒ (left, arg)
      }
    }
  }
  sealed trait Term {
    def count: Int
    def value: Option[Int]
  }
  sealed trait BiOp extends Term
  class HighPriority(left: Term, right: Term) extends BiOp {
    override val count: Int = left.count + right.count
    override val value: Option[Int] = left.value.flatMap(a ⇒ right.value.map(a * _)).filter(v ⇒ 0 <= v && v < 1024)
  }
  class Add(left: Term, right: Term) extends BiOp {
    override val count: Int = left.count + right.count
    override val value: Option[Int] = left.value.map(a ⇒ a.+(_: Int)).flatMap(right.value.map).filter(v ⇒ 0 <= v && v < 1024)
  }
  class Sub(left: Term, right: Term) extends BiOp {
    override val count: Int = left.count + right.count
    override val value: Option[Int] = left.value.map(a ⇒ a.-(_: Int)).flatMap(right.value.map).filter(v ⇒ 0 <= v && v < 1024)
  }
  case class Bracket(term: Term) extends Term {
    override def count: Int = 1
    override def value: Option[Int] = term.value
  }
  class Number(v: Int) extends Term {
    override def count: Int = 1
    override def value: Option[Int] = Some(v).filter(v ⇒ 0 <= v && v < 1024)
  }
}
