#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  string st;
  cin >> st;
  int a[6], add[6];
  int dif = 0;
  for (int i = 0; i < 6; ++i)
    a[i] = st[i] - '0', dif += a[i] * (i < 3 ? 1 : -1);
  for (int i = 0; i < 6; ++i) add[i] = (i < 3 ? (9 - a[i]) : a[i]);
  sort(add, add + 6);
  if (dif > 0) {
    int i = 0;
    while (dif > 0) dif -= 9 - add[i++];
    cout << i;
  } else {
    int i = 5;
    while (dif < 0) dif += add[i--];
    cout << 5 - i;
  }
}
