#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, t, s, w, q;
  char e[6];
  int a[3], b[3], d[6], c[6];
  cin >> e;
  for (int i = 0; i < 6; i++) c[i] = e[i] - 48;
  a[0] = c[0];
  a[1] = c[1];
  a[2] = c[2];
  b[0] = c[3];
  b[1] = c[4];
  b[2] = c[5];
  t = a[0] + a[1] + a[2];
  s = b[0] + b[1] + b[2];
  if (s == t) {
    cout << "0";
    return 0;
  }
  if (s > t) {
    k = s - t;
    for (int i = 0; i < 6; i++) d[i] = c[i];
  } else {
    k = t - s;
    d[0] = b[0];
    d[1] = b[1];
    d[2] = b[2];
    d[3] = a[0];
    d[4] = a[1];
    d[5] = a[2];
  }
  sort(d, d + 3);
  sort(d + 3, d + 6);
  w = 9 - d[0];
  q = 9 - d[1];
  if (d[5] >= k) {
    cout << "1";
    return 0;
  }
  if (w >= k) {
    cout << "1";
    return 0;
  }
  if (d[5] + d[4] >= k) {
    cout << "2";
    return 0;
  }
  if (d[5] + w >= k) {
    cout << "2";
    return 0;
  }
  if (w + q >= k) {
    cout << "2";
    return 0;
  }
  cout << "3";
  return 0;
}
