#include <bits/stdc++.h>
using namespace std;
int n;
int summ(int num) {
  return num % 10 + ((num - num % 10) / 10) % 10 + num / 100;
}
bool lucky(int num) { return summ(num % 1000) == summ(num / 1000); }
vector<int> numbers(int num) {
  vector<int> ans;
  for (int i = 0; i < 6; i++) {
    ans.push_back(num % 10);
    num /= 10;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int change(int num1, int num2) {
  vector<int> v1 = numbers(num1);
  vector<int> v2 = numbers(num2);
  int res = 0;
  for (int i = 0; i < 6; i++) {
    if (v1[i] != v2[i]) res++;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  int result = 100;
  for (int i = 0; i < 1000000; i++) {
    if (!lucky(i)) continue;
    int r = change(i, n);
    result = min(result, r);
  }
  printf("%d", result);
  return 0;
}
