object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  val state = new State(readLine.trim)
  implicit val target = readLine.trim.toList
    println(searchMaxCount(state, target).left.get)
  def searchMaxCount(state: State, rest: List[Char], currentPosition: Int = 0, depth: Int = 30, maxSuccessDepth: Int = 0)(implicit target: List[Char]): Either[Int, Int] = {
    if (depth == 0) Right(currentPosition)
    else {
      rest match {
        case Nil ⇒ searchMaxCount(state, target, currentPosition, depth - 1, maxSuccessDepth)
        case h::t ⇒
          searchMaxCount(state, target, currentPosition, depth - 1, maxSuccessDepth) match {
            case l@Left(_) ⇒ l
            case Right(position) ⇒
              state.nextIndex(position, h) match {
                case Some(next) ⇒ searchMaxCount(state, t, next + 1, depth, math.max(depth - 1, maxSuccessDepth))
                case None ⇒ Left(math.max(depth - 1, maxSuccessDepth))
              }
          }
      }
    }
  }

  class State(state: String){
    val length: Int = state.length
    val indices: Range = state.indices
    private val mLowerIndices = ('a' to 'z').map{c ⇒ state.zipWithIndex.filter(_._1 == c).map(_._2).toArray}.toArray
    private val mUpperIndices = ('A' to 'Z').map{c ⇒ state.zipWithIndex.filter(_._1 == c).map(_._2).toArray}.toArray
    def nextIndex(current: Int, target: Char): Option[Int] = {
      val array = if (target.isUpper) mUpperIndices(target - 'A') else mLowerIndices(target - 'a')
      val index = lowerBound(array, current)
      if (array.indices.contains(index)) Some(array(index))
      else None
    }
  }
  @inline
  def lowerBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  @inline
  def upperBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
