#include <bits/stdc++.h>
using namespace std;
int f(char c) { return (int)(c - '0'); }
int main() {
  string s;
  cin >> s;
  int s1 = 0, s2 = 0;
  vector<int> v(10);
  for (int i = 0; i < 6; i++) {
    v[i] = f(s[i]);
  }
  s1 = v[0] + v[1] + v[2];
  s2 = v[3] + v[4] + v[5];
  if (s1 > s2) {
    swap(v[0], v[3]);
    swap(v[1], v[4]);
    swap(v[2], v[5]);
    swap(s1, s2);
  }
  vector<int> t(6);
  for (int i = 0; i < 3; i++) {
    t[i] = 9 - v[i];
  }
  for (int i = 3; i < 6; i++) {
    t[i] = v[i];
  }
  sort(t.begin(), t.end());
  t.push_back(0);
  for (int i = 5; i >= 0; i--) {
    t[i] += t[i + 1];
  }
  int tmp = abs(s2 - s1);
  int it = 6;
  while (t[it] < tmp) {
    it--;
  }
  cout << 6 - it << endl;
}
