#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  string s;
  cin >> s;
  vector<int> b;
  vector<int> e;
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < 3; i++) {
    b.push_back((int)s[i] - 48);
    sum1 += b[i];
  }
  for (int i = 3; i < 6; i++) {
    e.push_back((int)s[i] - 48);
    sum2 += ((int)s[i] - 48);
  }
  sort(b.begin(), b.end());
  sort(e.begin(), e.end());
  if (sum1 == sum2) {
    cout << 0;
    return 0;
  }
  if (sum2 > sum1) {
    swap(b, e);
    swap(sum2, sum1);
  }
  vector<int> diff;
  for (int i = 0; i < e.size(); i++) {
    diff.push_back((9 - e[i]));
    diff.push_back(abs(0 - b[i]));
  }
  sort(diff.rbegin(), diff.rend());
  int delta = sum1 - sum2;
  int res = 0;
  for (int i = 0; i < 3; i++) {
    res++;
    if (delta - diff[i] > 0) {
      delta -= diff[i];
    } else {
      break;
    }
  }
  cout << res;
  return 0;
}
