#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, sum1 = 0, sum2 = 0;
  string s;
  cin >> s;
  int a[3], b[3];
  for (i = 0; i < 3; i++) {
    a[i] = s[i] - 48;
    sum1 += a[i];
    b[i] = s[5 - i] - 48;
    sum2 += b[i];
  }
  sort(a, a + 3);
  sort(b, b + 3);
  if (sum1 < sum2) {
    if (abs(sum1 - sum2) <= (9 - a[0]) || abs(sum1 - sum2) <= b[2])
      cout << 1;
    else if (abs(sum1 - sum2) <= max(9 - a[0], b[2]) + max(max(9 - a[1], b[1]),
                                                           min(9 - a[0], b[2])))
      cout << 2;
    else
      cout << 3;
  } else if (sum1 > sum2) {
    if (abs(sum1 - sum2) <= (9 - b[0]) || abs(sum1 - sum2) <= a[2])
      cout << 1;
    else if (abs(sum1 - sum2) <= max(9 - b[0], a[2]) + max(max(9 - b[1], a[1]),
                                                           min(9 - b[0], a[2])))
      cout << 2;
    else
      cout << 3;
  } else
    cout << 0;
}
