object Main extends App {
  def count(seq: Seq[StepAction]): Int = {
    val aerobics = new Aerobics(Down)
    seq.foreach(aerobics.action)
    aerobics.count
  }

  def solve(): Unit = {
    while (AerobicsReader.hasNext()) {
      println(count(AerobicsReader.next()))
    }
  }

  solve()
}

class Aerobics(var currentState: AerobicsState) {
  var objectiveState = currentState.nextObject
  var count = 0

  def action(action: StepAction): Unit = {
    currentState = currentState.transition(action)
    if (currentState == objectiveState) {
      count += 1
      objectiveState = currentState.nextObject
    }
  }
}

object AerobicsReader extends StepAction {
  def hasNext(): Boolean = {
    io.StdIn.readLine().toInt > 0
  }

  def next(): Seq[StepAction] = {
    io.StdIn.readLine().split("\\s").map(valueOf).toSeq
  }
}

/*
 ?¶???????????????¨?????????
 */
sealed trait StepAction {

  val valueOf = (code: String) => {
    code match {
      case "lu" => LeftUp
      case "ru" => RightUp
      case "ld" => LeftDown
      case "rd" => RightDown
      case _ => throw new NoSuchElementException(code + ": unexpected token")
    }
  }
}

case object LeftUp extends StepAction

case object RightUp extends StepAction

case object LeftDown extends StepAction

case object RightDown extends StepAction


/*
 ????¶??????¶????????¨?????????
 */
sealed trait AerobicsState {
  val nextObject: AerobicsState = null

  def transition(action: StepAction): AerobicsState
}

case object Down extends AerobicsState {
  override val nextObject = Up

  override def transition(action: StepAction): AerobicsState = {
    action match {
      case LeftUp => UpOnlyLeft
      case RightUp => UpOnlyRight
    }
  }
}

case object UpOnlyLeft extends AerobicsState {
  override def transition(action: StepAction): AerobicsState = {
    action match {
      case RightUp => Up
      case LeftDown => Down
    }
  }
}

case object UpOnlyRight extends AerobicsState {
  override def transition(action: StepAction): AerobicsState = {
    action match {
      case LeftUp => Up
      case RightDown => Down
    }
  }

}

case object Up extends AerobicsState {
  override val nextObject = Down

  override def transition(action: StepAction): AerobicsState = {
    action match {
      case LeftDown => UpOnlyRight
      case RightDown => UpOnlyLeft
    }
  }
}