#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 998244353;
const int Max = 1e5 + 10;
const int Max2 = 1e3 + 10;
int n, m, k;
char str[Max];
int add[Max];
int main() {
  while (scanf("%s", str) != EOF) {
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < 6; i++) {
      add[i] = '9' - str[i];
      if (i < 3)
        sum1 += str[i] - '0';
      else
        sum2 += str[i] - '0';
    }
    if (sum1 < sum2) {
      for (int i = 3; i < 6; i++) add[i] = str[i] - '0';
      sort(add, add + 6);
      int use = 0;
      while (sum1 < sum2) sum1 += add[5 - use++];
      printf("%d\n", use);
    } else {
      for (int i = 0; i < 3; i++) add[i] = str[i] - '0';
      sort(add, add + 6);
      int use = 0;
      while (sum2 < sum1) sum2 += add[5 - use++];
      printf("%d\n", use);
    }
  }
  return 0;
}
