#include <bits/stdc++.h>
using namespace std;
long long fact[1006], inv[1006];
long long fp(long long base, long long exp) {
  if (exp == 0) return 1;
  long long ans = fp(base, exp / 2);
  ans = (ans * ans) % 1000000007;
  if (exp % 2 != 0) ans = (ans * (base % 1000000007)) % 1000000007;
  return ans;
}
void calcFacAndInv(long long n) {
  fact[0] = inv[0] = 1;
  for (long long i = 1; i <= n; i++) {
    fact[i] = (i * fact[i - 1]) % 1000000007;
    inv[i] = fp(fact[i], 1000000007 - 2);
  }
}
long long ncr(long long n, long long r) {
  return ((fact[n] * inv[r]) % 1000000007 * inv[n - r]) % 1000000007;
}
int main() {
  string s;
  cin >> s;
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < 6; i++) {
    if (i <= 2)
      sum1 += ((int)s[i] - 48);
    else
      sum2 += ((int)s[i] - 48);
  }
  int mini = 1e3;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        int cnt = 0;
        if (i + j + k == sum1) {
          if (i != ((int)s[3]) - 48) cnt++;
          if (j != ((int)s[4]) - 48) cnt++;
          if (k != ((int)s[5]) - 48) cnt++;
          mini = min(cnt, mini);
        }
      }
    }
  }
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        int cnt = 0;
        if (i + j + k == sum2) {
          if (i != ((int)s[0]) - 48) cnt++;
          if (j != ((int)s[1]) - 48) cnt++;
          if (k != ((int)s[2]) - 48) cnt++;
          mini = min(cnt, mini);
        }
      }
    }
  }
  cout << mini << endl;
  return 0;
}
