#include <bits/stdc++.h>
using namespace std;
const double pi = 4 * atan(1.0);
const int MAXN = 100010;
const int MAXM = 2 * MAXN;
bool cmp(int a, int b) { return (a > b); }
int main() {
  int a[10], num1, num2, s, ans;
  string str;
  cin >> str;
  num1 = str[0] + str[1] + str[2] - 3 * '0';
  num2 = str[3] + str[4] + str[5] - 3 * '0';
  ans = 0;
  if (num1 == num2)
    cout << 0 << endl;
  else if (num1 < num2) {
    a[0] = 9 - (str[0] - '0');
    a[1] = 9 - (str[1] - '0');
    a[2] = 9 - (str[2] - '0');
    a[3] = str[3] - '0';
    a[4] = str[4] - '0';
    a[5] = str[5] - '0';
    sort(a, a + 6, cmp);
    s = num2 - num1;
    while (s > 0) {
      s -= (a[ans++]);
    }
    cout << ans << endl;
  } else if (num1 > num2) {
    a[0] = str[0] - '0';
    a[1] = str[1] - '0';
    a[2] = str[2] - '0';
    a[3] = 9 - (str[3] - '0');
    a[4] = 9 - (str[4] - '0');
    a[5] = 9 - (str[5] - '0');
    sort(a, a + 6, cmp);
    s = num1 - num2;
    while (s > 0) {
      s -= (a[ans++]);
    }
    cout << ans << endl;
  }
  return 0;
}
