#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a[6];
  int b[6];
  for (int i = 0; i < 6; i++) a[i] = s[i] - '0';
  int lsum = a[0] + a[1] + a[2];
  int rsum = a[3] + a[4] + a[5];
  int cnt = 0, dif = abs(lsum - rsum);
  if (dif == 0)
    cnt = 0;
  else if (lsum < rsum) {
    b[0] = 9 - a[0];
    b[1] = 9 - a[1];
    b[2] = 9 - a[2];
    b[3] = a[3];
    b[4] = a[4];
    b[5] = a[5];
    sort(b, b + 6);
    int sum = 0, j;
    for (j = 0; j < 6; j++) {
      sum += b[5 - j];
      if (sum >= dif) break;
    }
    cnt = j + 1;
  } else {
    b[0] = 9 - a[3];
    b[1] = 9 - a[4];
    b[2] = 9 - a[5];
    b[3] = a[0];
    b[4] = a[1];
    b[5] = a[2];
    sort(b, b + 6);
    int sum = 0, j;
    for (j = 0; j < 6; j++) {
      sum += b[5 - j];
      if (sum >= dif) break;
    }
    cnt = j + 1;
  }
  cout << cnt << endl;
  return 0;
}
