#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int main() {
  string s;
  cin >> s;
  int ans = 100;
  for (int i = 0; i < int(1e7); ++i) {
    string ss = to_string(i);
    reverse(ss.begin(), ss.end());
    while ((int)(ss.size()) < 6) ss.push_back('0');
    reverse(ss.begin(), ss.end());
    int s1 = 0, s2 = 0;
    for (int i = 0; i < 3; i++) s1 += (ss[i] - '0'), s2 += (ss[5 - i] - '0');
    if (s1 != s2) continue;
    int diff = 0;
    for (int i = 0; i < 6; i++)
      if (s[i] != ss[i]) diff++;
    ans = min(ans, diff);
  }
  printf("%d\n", ans);
  return 0;
}
