#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a[6];
  for (int i = 0; i < 6; i++) {
    a[i] = s[i] - 48;
  }
  int sum1 = a[0] + a[1] + a[2];
  int sum2 = a[3] + a[4] + a[5];
  int difference = abs(sum1 - sum2);
  int flag = 0;
  if (sum1 > sum2) flag = 3;
  for (int i = flag; i <= flag + 2; i++) {
    a[i] = 9 - a[i];
  }
  int count = 0;
  int sum = 0;
  if (difference == 0) {
    cout << 0 << endl;
    return 0;
  }
  while (1) {
    int maxi = 0;
    for (int i = 0; i < 6; i++) {
      if (a[maxi] < a[i]) maxi = i;
    }
    if (a[maxi] == -1) return 0;
    count += 1;
    sum += a[maxi];
    if (sum >= difference) {
      cout << count << endl;
      return 0;
    }
    a[maxi] = -1;
  }
}
