#include <bits/stdc++.h>
using namespace std;
int a, b, m, n = 5, k;
string s;
int main() {
  cin >> s;
  for (int i = 0; i < 3; i++) a += s[i] - 48;
  for (int i = 3; i < 6; i++) b += s[i] - 48;
  if (a > b) {
    for (int i = 3; i < 6; i++) s[i] = 9 - (s[i] - 48) + 48;
    sort(s.begin(), s.end());
  } else {
    for (int i = 0; i < 3; i++) s[i] = 9 - (s[i] - 48) + 48;
    sort(s.begin(), s.end());
  }
  k = abs(a - b);
  while (k > 0) {
    m++;
    k -= s[n--] - 48;
  }
  cout << m;
}
