#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= 11 && col >=0 && col<= 11)return true;
	else{
		return false;
	}
}

void erase(char buf[12][13],int row,int col){
	buf[row][col] = '0';
	if(rangeCheck(row,col-1)&&buf[row][col-1] == '1')erase(buf,row,col-1);
	if(rangeCheck(row+1,col)&&buf[row+1][col] == '1')erase(buf,row+1,col);
	if(rangeCheck(row,col+1)&&buf[row][col+1] == '1')erase(buf,row,col+1);
}

int main(){

	char buf[12][13];
	int count;

	while(scanf("%s",buf[0])!=EOF){
		for(int i=1; i <= 11; i++){
			scanf("%s",buf[i]);
		}
		getchar();
		count = 0;

		for(int i=0; i < 12; i++){
			for(int k=0; k < 12; k++){
				if(buf[i][k] == '1'){
					count++;
					erase(buf,i,k);
				}
			}
		}

		printf("%d\n",count);
	}
	return 0;
}
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N;
  cin >> N;
  int n = N.length();
  long long dp[n + 1][2];
  dp[n][0] = 0;
  dp[n][1] = 0;
  for (int i = n - 1; i >= 0; i--) {
    dp[i][0] = INT_MAX;
    dp[i][1] = INT_MAX;
    int dig = N[i] - '0';
    for (int j = 0; j < 10 - dig; j++) {
      dp[i][0] = min(dp[i][0], dp[i + 1][0] + j + j + dig);
    }
    for (int j = 0; j + 1 < 10 - dig; j++) {
      dp[i][0] = min(dp[i][0], dp[i + 1][1] + j + j + dig + 1);
    }
    for (int j = 10 - dig; j < 10; j++) {
      dp[i][1] = min(dp[i][1], dp[i + 1][0] + j + (j + dig) % 10);
    }
    if (i < n - 1)
      for (int j = 9 - dig; j < 10; j++) {
        dp[i][1] = min(dp[i][1], dp[i + 1][1] + j + (j + dig + 1) % 10);
      }
  }
  long long ans = min(dp[0][0], dp[0][1] + 1);
  cout << ans << endl;
  return 0;
}
