#include <bits/stdc++.h>
using namespace std;
long long cou = 0, ans = 0, mx = INT_MIN, mn = INT_MAX, sum = 0;
int main() {
  string s;
  cin >> s;
  vector<long long> v, b;
  for (int x = 0; x < 3; x++) {
    v.push_back(s[x] - 48);
    sum += v.back();
  }
  for (int x = 3; x < s.size(); x++) {
    b.push_back(s[x] - 48);
    cou += b.back();
  }
  if (sum > cou) {
    for (int x = 0; x < 3; x++) {
      b[x] = 9 - b[x];
    }
  } else {
    for (int x = 0; x < 3; x++) {
      v[x] = 9 - v[x];
    }
  }
  for (int x = 0; x < 3; x++) {
    v.push_back(b[x]);
  }
  sort(v.begin(), v.end());
  cou = abs(cou - sum);
  while (cou) {
    cou -= min(cou, v.back());
    v.pop_back();
    ans++;
  }
  cout << ans;
  return 0;
}
