#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long int a, b, c, d, e, f, i, j, ans = 9;
  for (a = 0; a <= 9; a++) {
    for (b = 0; b <= 9; b++) {
      for (c = 0; c <= 9; c++) {
        for (d = 0; d <= 9; d++) {
          for (e = 0; e <= 9; e++) {
            for (f = 0; f <= 9; f++) {
              long long int count = 0;
              if (a + b + c == d + e + f) {
                if (a != s[0] - '0') {
                  count++;
                }
                if (b != s[1] - '0') {
                  count++;
                }
                if (c != s[2] - '0') {
                  count++;
                }
                if (d != s[3] - '0') {
                  count++;
                }
                if (e != s[4] - '0') {
                  count++;
                }
                if (f != s[5] - '0') {
                  count++;
                }
                ans = min(count, ans);
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
