#!/usr/bin/python2 # -*- coding: utf-8 -*- # † # 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 bs = [1, 0, 0, 0, 1, 0, 1, 0, 2, 1] s = raw_input() # 数字の外, 数字の中, 数字そのもの a, b, c = 1, 0, len(s) for ch in s: b += bs[int(ch)] res1 = a + b + 2 * c res2 = 2 * (a + b) + c mini = min(res1, res2) print mini