object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)

	pw.println(sc.next.toSeq.map(_.asDigit).reverse.foldLeft((0, false)) { case ((z, carry), x) =>
		val y = x + (if (carry) 1 else 0)
		(z + (if (y > 5) 1 else y), y > 5)
	})
	pw.flush()
}