#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string str;
  cin >> str;
  vector<long long int> v1, v2;
  for (long long int i = 0; i < 3; i++) v1.push_back(str[i] - '0');
  for (long long int i = 3; i < 6; i++) v2.push_back(str[i] - '0');
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  long long int sum1 = 0;
  long long int sum2 = 0;
  for (long long int i = 0; i < 3; i++) sum1 += v1[i];
  for (long long int i = 0; i < 3; i++) sum2 += v2[i];
  if (sum1 == sum2) {
    cout << "0" << endl;
    return 0;
  } else if (sum1 > sum2) {
    swap(sum1, sum2);
    for (long long int i = 0; i < 3; i++) {
      long long int temp = v1[i];
      v1[i] = v2[i];
      v2[i] = temp;
    }
  }
  if ((sum1 - v1[0] + 9) >= sum2) {
    cout << "1";
    return 0;
  }
  if ((sum2 - v2[2]) <= sum1) {
    cout << "1";
    return 0;
  }
  if ((18 + v1[2]) >= sum2 || (v2[0] <= sum1)) {
    cout << "2";
    return 0;
  }
  if ((9 + v1[1] + v1[2]) >= (v2[0] + v2[1])) {
    cout << "2";
    return 0;
  }
  cout << "3";
  return 0;
}
