#include <bits/stdc++.h>
using namespace std;
const int MAXN = 7;
int a[MAXN];
string s;
int main(void) {
  int cnt1 = 0, cnt2 = 0, cnt = 0, sol = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    a[i] = s[i] - '0';
    if (i < 3)
      cnt1 += a[i];
    else
      cnt2 += a[i];
  }
  if (cnt1 < cnt2) {
    cnt = cnt2 - cnt1;
    for (int i = 0; i < 3; i++) {
      a[i] = 9 - a[i];
    }
  } else if (cnt1 > cnt2) {
    cnt = cnt1 - cnt2;
    for (int i = 3; i < 6; i++) {
      a[i] = 9 - a[i];
    }
  }
  sort(a, a + 6);
  for (int i = 5; i >= 0; i--) {
    if (cnt <= 0) break;
    cnt -= a[i];
    sol++;
  }
  cout << sol << endl;
  return 0;
}
