#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[6];
  for (int i = 0; i < 6; i++) scanf("%1d", &arr[i]);
  int big_sum = 0;
  int small_sum = 0;
  big_sum = arr[0] + arr[1] + arr[2];
  small_sum = arr[3] + arr[4] + arr[5];
  if (small_sum > big_sum) swap(small_sum, big_sum);
  int diff = big_sum - small_sum;
  int sm_left = arr[0] + arr[1] + arr[2];
  int sm_rgt = arr[3] + arr[4] + arr[5];
  int scope[6];
  if (sm_left > sm_rgt) {
    for (int i = 0; i < 3; i++) scope[i] = arr[i];
    for (int i = 3; i < 6; i++) scope[i] = 9 - arr[i];
  } else {
    for (int i = 0; i < 3; i++) scope[i] = 9 - arr[i];
    for (int i = 3; i < 6; i++) scope[i] = arr[i];
  }
  sort(scope, scope + 6, greater<int>());
  int i;
  for (i = 0; i < 6; i++) {
    if (diff <= 0) break;
    diff -= scope[i];
  }
  cout << i;
}
