#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int temp = 10;
  int cntr = 0;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int z = 0; z <= 9; z++) {
        for (int a = 0; a <= 9; a++) {
          for (int b = 0; b <= 9; b++) {
            for (int c = 0; c <= 9; c++) {
              if (i + j + z == a + b + c) {
                if ((s[0] - '0') != i) cntr++;
                if ((s[1] - '0') != j) cntr++;
                if ((s[2] - '0') != z) cntr++;
                if ((s[3] - '0') != a) cntr++;
                if ((s[4] - '0') != b) cntr++;
                if ((s[5] - '0') != c) cntr++;
                cntr = min(cntr, temp);
                temp = cntr;
                cntr = 0;
              }
            }
          }
        }
      }
    }
  }
  cout << temp;
}
