#include <bits/stdc++.h>
using namespace std;
int main() {
  int ticket[6], a, b, c, d, e, f, tmp, res = 6;
  string input;
  cin >> input;
  for (a = 0; a < 6; a++) ticket[a] = input[a] - '0';
  for (a = 0; a < 10; a++) {
    for (b = 0; b < 10; b++) {
      for (c = 0; c < 10; c++) {
        for (d = 0; d < 10; d++) {
          for (e = 0; e < 10; e++) {
            for (f = 0; f < 10; f++) {
              if (a + b + c == d + e + f) {
                tmp = 0;
                if (a != ticket[0]) tmp++;
                if (b != ticket[1]) tmp++;
                if (c != ticket[2]) tmp++;
                if (d != ticket[3]) tmp++;
                if (e != ticket[4]) tmp++;
                if (f != ticket[5]) tmp++;
                if (!tmp) {
                  cout << 0 << endl;
                  return 0;
                }
                res = min(res, tmp);
              }
            }
          }
        }
      }
    }
  }
  cout << res << endl;
}
