#include <bits/stdc++.h>
using namespace std;
string x;
int p = 0, k = 13;
int main() {
  cin >> x;
  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)) {
                p += (a != x[0] - 48) + (b != x[1] - 48) + (c != x[2] - 48) +
                     (d != x[3] - 48) + (e != x[4] - 48) + (f != x[5] - 48);
                k = min(p, k);
                p = 0;
              }
            }
          }
        }
      }
    }
  }
  cout << k << endl;
  return 0;
}
