#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[7];
  scanf("%s", s);
  int a[6];
  for (int i = 0; i < 6; i++) a[i] = s[i] - '0';
  int sum1 = a[0] + a[1] + a[2];
  int sum2 = a[3] + a[4] + a[5];
  if (sum2 == sum1) {
    printf("0\n");
    return 0;
  }
  if (sum2 > sum1) {
    swap(a[0], a[3]);
    swap(a[1], a[4]);
    swap(a[2], a[5]);
    swap(sum2, sum1);
  }
  a[3] = 9 - a[3];
  a[4] = 9 - a[4];
  a[5] = 9 - a[5];
  int aim = sum1 - sum2;
  sort(a, a + 6);
  int now = 0;
  int p = 0;
  for (int i = 5; i >= 0; i--) {
    now += a[i];
    p++;
    if (aim <= now) break;
  }
  printf("%d\n", p);
}
