#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
  string s;
  cin >> s;
  int ans = numeric_limits<int>::max();
  for (int i = 0; i < 10; ++i)
    for (int j = 0; j < 10; ++j)
      for (int k = 0; k < 10; ++k)
        for (int a = 0; a < 10; ++a)
          for (int b = 0; b < 10; ++b)
            for (int c = 0; c < 10; ++c) {
              if (c + b + a != i + j + k) continue;
              int mn = 0;
              mn += (s[0] - '0' != i);
              mn += (s[1] - '0' != j);
              mn += (s[2] - '0' != k);
              mn += (s[3] - '0' != a);
              mn += (s[4] - '0' != b);
              mn += (s[5] - '0' != c);
              ans = min(mn, ans);
            }
  cout << ans << '\n';
  return 0;
}
