#include <bits/stdc++.h>
using namespace std;
string s;
int first = 0, last;
int main() {
  cin >> s;
  int ans, ans1, ans2;
  int final = INT_MAX;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        for (int l = 0; l <= 9; l++) {
          for (int m = 0; m <= 9; m++) {
            for (int n = 0; n <= 9; n++) {
              ans = 0;
              first = i + j + k;
              last = l + m + n;
              if (last != first)
                continue;
              else {
                if (s[0] - '0' != i) ans++;
                if (s[1] - '0' != j) ans++;
                if (s[2] - '0' != k) ans++;
                if (s[3] - '0' != l) ans++;
                if (s[4] - '0' != m) ans++;
                if (s[5] - '0' != n) ans++;
                final = min(final, ans);
              }
            }
          }
        }
      }
    }
  }
  cout << final << "\n";
}
