#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int neginf = 0xc0c0c0c0;
bool cmp(const int& a, const int& b) { return abs(a) < abs(b); }
int doit(string& s1, string& s2) {
  int sumA = 0;
  int sumB = 0;
  for (char c : s1) sumA += c - '0';
  for (char c : s2) sumB += c - '0';
  if (sumA < sumB) {
    swap(s1, s2);
    swap(sumA, sumB);
  }
  int need = sumA - sumB;
  vector<int> can;
  for (char c : s2) can.push_back(9 - (c - '0'));
  for (char c : s1) can.push_back(c - '0');
  int resp = 0;
  sort((can).begin(), (can).end());
  while (need) {
    int lst = can.back();
    if (lst >= need) {
      return resp + 1;
    } else {
      resp++;
      need -= lst;
      can.pop_back();
    }
  }
  return resp;
}
int main() {
  string s;
  cin >> s;
  string fst, snd;
  for (int(i) = (0); (i) < (6); ++(i)) {
    if (i < 3)
      fst += s[i];
    else
      snd += s[i];
  }
  cout << doit(fst, snd) << endl;
  return 0;
}
