#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double pi = acos(-1.0);
string replace(string s) {
  string k = "";
  if (s.length() < 6) {
    long long dif = 6 - s.length();
    for (long long i = 0; i < dif; i += 1) {
      k += '0';
    }
  }
  k += s;
  return k;
}
bool check(string s) {
  long long c1 = 0;
  long long c2 = 0;
  for (long long i = 0; i < 3; i++) {
    c1 += s[i] - '0';
  }
  for (long long i = 3; i < 6; i++) {
    c2 += s[i] - '0';
  }
  if (c1 == c2)
    return true;
  else
    return false;
}
long long val(string x, string y) {
  long long cnt = 0;
  for (long long i = 0; i < x.length(); i++) {
    if (x[i] != y[i]) {
      cnt++;
    }
  }
  return cnt;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tt;
  tt = 1;
  while (tt--) {
    string s;
    cin >> s;
    long long ans = MOD;
    for (long long i = 0; i <= 1000000; i++) {
      string g = to_string(i);
      g = replace(g);
      if (check(g)) {
        ans = min(ans, val(g, s));
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
