#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long int logy(long long int x, long long int y) {
  return ceil((long double)(log(x) / log(y)));
}
long long int powe(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b & 1) re = (re * a) % 1000000009;
    a = (a * a) % 1000000009;
    b = b >> 1;
  }
  return re % 1000000009;
}
bool flag = 0, flag1 = 0, flag2 = 0;
vector<long long> vv[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long int a[6], s1 = 0, s2 = 0;
  for (long long int i = 0; i < 6; i++) a[i] = s[i] - '0';
  sort(a, a + 3);
  sort(a + 3, a + 6);
  for (long long int i = 0; i < 3; i++) s1 += a[i];
  for (long long int i = 3; i < 6; i++) s2 += a[i];
  if (s2 < s1) {
    swap(a[0], a[3]);
    swap(a[1], a[4]);
    swap(a[2], a[5]);
  }
  long long int d[6] = {0}, ans = 0;
  for (long long int i = 0; i < 3; i++) d[i] = abs(9 - a[i]);
  for (long long int i = 3; i < 6; i++) d[i] = abs(a[i]);
  sort(d, d + 6);
  reverse(d, d + 6);
  long long int dif = abs(s1 - s2);
  for (long long int i = 0; i < 3; i++) {
    if (dif > 0) ans++, dif -= d[i];
  }
  cout << ans;
  return 0;
}
