#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double pii = 3.14159265359;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str;
  cin >> str;
  vector<int> v(6);
  for (int x = 0; x < (6); x++) v[x] = str[x] - '0';
  vector<int> val(6);
  int mn = INT_MAX;
  for (int z = 0; z < (10); z++) {
    if (z == v[0])
      val[0] = 1;
    else
      val[0] = 0;
    for (int b = 0; b < (10); b++) {
      if (b == v[1])
        val[1] = 1;
      else
        val[1] = 0;
      for (int c = 0; c < (10); c++) {
        if (c == v[2])
          val[2] = 1;
        else
          val[2] = 0;
        for (int d = 0; d < (10); d++) {
          if (d == v[3])
            val[3] = 1;
          else
            val[3] = 0;
          for (int e = 0; e < (10); e++) {
            if (e == v[4])
              val[4] = 1;
            else
              val[4] = 0;
            for (int first = 0; first < (10); first++) {
              if (first == v[5])
                val[5] = 1;
              else
                val[5] = 0;
              if (z + b + c == d + e + first)
                ckmin(mn, 6 - (val[0] + val[1] + val[2] + val[3] + val[4] +
                               val[5]));
            }
          }
        }
      }
    }
  }
  cout << mn << nl;
  return 0;
}
