#include <bits/stdc++.h>
using namespace std;
void recurse(string s, vector<string> &v) {
  if (s.size() == 6) {
    int cnt1 = 0;
    cnt1 = s[0] - '0' + s[1] - '0' + s[2] - '0';
    int cnt2 = s[3] - '0' + s[4] - '0' + s[5] - '0';
    if (cnt1 == cnt2) {
      v.push_back(s);
    }
    return;
  }
  for (char i = '0'; i <= '9'; i++) {
    recurse(s + i, v);
  }
}
int main() {
  string s;
  cin >> s;
  vector<string> v;
  recurse("", v);
  int ans = 6;
  for (int i = 0; i < v.size(); i++) {
    int cnt = 0;
    for (int j = 0; j < v[i].size(); j++) {
      if (s[j] != v[i][j]) cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}
