#include <bits/stdc++.h>
using namespace std;
long long int B[6];
long long int ans;
void rec(long long int p, long long int A[]) {
  if (p == 6) {
    long long int sum1 = 0, sum2 = 0;
    for (long long int i = 0; i < 6 / 2; i += 1) sum1 += B[i];
    for (long long int i = 6 / 2; i < 6; i += 1) sum2 += B[i];
    if (sum1 == sum2) {
      long long int cnt = 0;
      for (long long int i = 0; i < 6; i += 1)
        if (A[i] != B[i]) cnt++;
      ans = min(ans, cnt);
    }
    return;
  }
  for (long long int i = 0; i < 10; i += 1) {
    B[p] = i;
    rec(p + 1, A);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  long long int A[6];
  for (long long int i = 0; i < 6; i += 1) {
    A[i] = (long long int)s[i] - 48;
  }
  ans = std::numeric_limits<long long int>::max();
  rec(0, A);
  cout << ans;
  return 0;
}
