#include <bits/stdc++.h>
using namespace std;
inline long long in() {
  long long x;
  scanf("%d", &x);
  return x;
}
ifstream fin("my code.txt");
int max(int a, int b, int c) {
  if (a > b) swap(a, b);
  if (a > c) swap(a, c);
  if (b > c) swap(b, c);
  return c;
}
int f(int *a, int *b, int s1, int s2) {
  if (s2 + (9 - b[0]) >= s1 || s1 - (a[2]) <= s2) return 1;
  int m = max(a[2] + a[1], (9 - b[0] + 9 - b[1]), (9 - b[0] + a[2]));
  if (m >= s1 - s2) return 2;
  return 3;
}
int main() {
  string str;
  cin >> str;
  int i, s1 = 0, s2 = 0;
  int a[3], b[3];
  for (i = 0; i < 3; i++) {
    a[i] = (str[i] - '0');
    s1 += a[i];
  }
  for (i = 3; i < 6; i++) {
    b[i - 3] = (str[i] - '0');
    s2 += b[i - 3];
  }
  sort(a, a + 3);
  sort(b, b + 3);
  if (s1 == s2)
    cout << 0;
  else if (s1 > s2)
    cout << f(a, b, s1, s2);
  else
    cout << f(b, a, s2, s1);
}
