#include <bits/stdc++.h>
using namespace std;
string s;
int a[3], b[3];
int cun1[6], cun2[6];
int cmp(int a, int b) { return a > b; }
int main() {
  cin >> s;
  int sum1 = 0;
  int sum2 = 0;
  for (int i = 0; i < 3; i++) {
    sum1 += s[i] - '0';
    a[i] = s[i] - '0';
    sum2 += s[i + 3] - '0';
    b[i] = s[i + 3] - '0';
  }
  int cha = abs(sum1 - sum2);
  if (sum2 > sum1) {
    int index = 0;
    for (int i = 0; i < 3; i++) {
      cun1[i] = b[i];
    }
    for (int i = 0; i < 3; i++) {
      cun1[i + 3] = 9 - a[i];
    }
    sort(cun1, cun1 + 6, cmp);
    int res = 0;
    while (cha > 0) {
      cha -= cun1[res++];
    }
    cout << res << endl;
  } else if (sum2 < sum1) {
    int index = 0;
    for (int i = 0; i < 3; i++) {
      cun2[i] = a[i];
    }
    for (int i = 0; i < 3; i++) {
      cun2[i + 3] = 9 - b[i];
    }
    sort(cun2, cun2 + 6, cmp);
    int res = 0;
    while (cha > 0) {
      cha -= cun2[res++];
    }
    cout << res << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
