#include <bits/stdc++.h>
using namespace std;
int check() {}
int main() {
  cout.precision(20);
  string s;
  cin >> s;
  int q[6];
  q[0] = s[0] - '0';
  q[1] = s[1] - '0';
  q[2] = s[2] - '0';
  q[3] = s[3] - '0';
  q[4] = s[4] - '0';
  q[5] = s[5] - '0';
  int ans = 10;
  for (int a = 0; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      for (int c = 0; c < 10; c++) {
        for (int d = 0; d < 10; d++) {
          for (int e = 0; e < 10; e++) {
            for (int f = 0; f < 10; f++) {
              if (a + b + c == d + e + f) {
                int kk = 0;
                if (q[0] != a) kk++;
                if (q[1] != b) kk++;
                if (q[2] != c) kk++;
                if (q[3] != d) kk++;
                if (q[4] != e) kk++;
                if (q[5] != f) kk++;
                ans = min(ans, kk);
              }
            }
          }
        }
      }
    }
  }
  cout << ans;
}
