#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int out = 3;
  for (int i = 0; i <= 999999; i++) {
    int n = i, sum = 0, dif = 0;
    for (int j = 0; j < 6; j++) {
      sum = j < 3 ? sum + n % 10 : sum - n % 10;
      dif += n % 10 != str[j] - 48;
      n /= 10;
    }
    if (!sum) out = min(out, dif);
  }
  cout << out;
  return 0;
}
