#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
  string s;
  cin >> s;
  long long sum1 = 0, sum2 = 0;
  for (int i = 0; i < 3; i++) sum1 += s[i] - '0';
  for (int i = 3; i < 6; i++) sum2 += s[i] - '0';
  long long diff = sum1 - sum2;
  if (diff == 0) {
    cout << "0\n";
    return 0;
  }
  if (diff > 0) {
    vector<long long> v;
    for (int i = 0; i < 3; i++) v.push_back(s[i] - '0');
    for (int i = 3; i < 6; i++) v.push_back(9 - (s[i] - '0'));
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    long long count = 0;
    for (int i = 0; i < 6; i++) {
      if (v[i] >= diff) {
        count++;
        cout << count << "\n";
        return 0;
      } else {
        count++;
        diff -= v[i];
      }
    }
  } else {
    diff *= -1;
    vector<long long> v;
    for (int i = 0; i < 3; i++) v.push_back(9 - (s[i] - '0'));
    for (int i = 3; i < 6; i++) v.push_back(s[i] - '0');
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    long long count = 0;
    for (int i = 0; i < 6; i++) {
      if (v[i] >= diff) {
        count++;
        cout << count << "\n";
        return 0;
      } else {
        count++;
        diff -= v[i];
      }
    }
  }
  return 0;
}
