#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e8;
const long long N = 1020;
const long long inf = 1e14;
void solve() {
  string s;
  cin >> s;
  long long sum1 = 0, sum2 = 0;
  for (long long i = 0; i < 3; i++) sum1 += (s[i] - '0');
  for (long long i = 3; i < 6; i++) sum2 += (s[i] - '0');
  long long ans = sum2 - sum1, fi = 6;
  for (long long mask = 0; mask < (1LL << 6); mask++) {
    long long mn = 0, mx = 0;
    for (long long j = 0; j < 3; j++) {
      if ((mask >> j) & 1) {
        mn += (s[j] - '0');
        mx += 9 - (s[j] - '0');
      }
    }
    for (long long j = 3; j < 6; j++) {
      if ((mask >> j) & 1) {
        mn += 9 - (s[j] - '0');
        mx += (s[j] - '0');
      }
    }
    long long x1 = ans + mn, x2 = ans - mx;
    if (x2 <= 0 && x1 >= 0) {
      fi = min(fi, (long long)__builtin_popcount(mask));
    }
  }
  cout << fi << endl;
}
int32_t main() {
  long long t = 1;
  while (t--) solve();
}
