#include <bits/stdc++.h>
using namespace std;
const long long cls = 1e9 + 7;
const int maxn = 1e6 + 10;
const double eps = 1e-13;
const double pi = acos(-1.0);
using namespace std;
int a[6];
int b[6];
int main() {
  string s;
  cin >> s;
  a[0] = s[0] - '0', a[1] = s[1] - '0', a[2] = s[2] - '0', a[3] = s[3] - '0',
  a[4] = s[4] - '0', a[5] = s[5] - '0';
  int ffirst = a[0] + a[1] + a[2];
  int ssecond = a[3] + a[4] + a[5];
  if (ffirst < ssecond) {
    for (int i = 0; i < 3; i++) {
      swap(a[i], a[i + 3]);
    }
  }
  for (int i = 0; i < 3; i++) {
    b[i] = a[i];
  }
  for (int i = 3; i < 6; i++) {
    b[i] = 9 - a[i];
  }
  sort(b, b + 6);
  int sum = 0;
  for (int i = 5; i >= 0; i--) {
    if (sum >= abs(ffirst - ssecond)) {
      printf("%d\n", 6 - i - 1);
      return 0;
    }
    sum += b[i];
  }
  printf("0\n");
  return 0;
}
