#include using namespace std; using ll = long long; const int INF = 1000000000; int dp[2][2]; int main() { cin.tie(0); ios::sync_with_stdio(false); string n; cin >> n; dp[0][0] = 0; dp[0][1] = INF; dp[1][0] = INF; dp[1][1] = INF; int m = n.length(); for (int i = 0; i < m; i++) { int cur = n[i] - '0'; switch (cur) { case 0: case 1: dp[(i + 1) % 2][0] = min(dp[i % 2][0], dp[i % 2][1] + 1) + cur; break; case 2: dp[(i + 1) % 2][0] = min(dp[i % 2][0], dp[i % 2][1] + 1) + cur; dp[(i + 1) % 2][1] = min(dp[i % 2][0], dp[i % 2][1]) + cur + 1; break; case 3: dp[(i + 1) % 2][0] = min(dp[i % 2][0], dp[i % 2][1] + 1) + 3; dp[(i + 1) % 2][1] = min(dp[i % 2][0], dp[i % 2][1]) + 2; break; case 4: dp[(i + 1) % 2][1] = min(dp[i % 2][0], dp[i % 2][1]) + 1; break; case 5: case 6: dp[(i + 1) % 2][0] = min(dp[i % 2][0], dp[i % 2][1]) + cur - 4; break; case 7: dp[(i + 1) % 2][0] = min(dp[i % 2][0], dp[i % 2][1]) + 3; dp[(i + 1) % 2][1] = min(dp[i % 2][0] + 1, dp[i % 2][1]) + 2; break; case 8: dp[(i + 1) % 2][1] = min(dp[i % 2][0] + 1, dp[i % 2][1]) + 1; break; case 9: dp[(i + 1) % 2][1] = min(dp[i % 2][0] + 1, dp[i % 2][1]); break; } dp[i % 2][0] = INF; dp[i % 2][1] = INF; } cout << min(dp[m % 2][0], dp[m % 2][1] + 1) << endl; return 0; }