#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int a[6];
  int sub = 0;
  for (size_t i = 0; i < 6; i++) {
    a[i] = s[i] - '0';
    sub += i < 3 ? a[i] : (-1) * a[i];
  }
  if (sub < 0) {
    a[0] = 9 - a[0];
    a[1] = 9 - a[1];
    a[2] = 9 - a[2];
  } else if (sub > 0) {
    a[3] = 9 - a[3];
    a[4] = 9 - a[4];
    a[5] = 9 - a[5];
  }
  sort(a, a + 6, greater<int>());
  sub = abs(sub);
  int ans = 0;
  for (size_t i = 0; sub > 0; i++) {
    ans++;
    sub -= a[i];
  }
  cout << ans;
  return 0;
}
