#include <bits/stdc++.h>
using namespace std;
double play(int n, queue<int> q[], int parent, int point, int len) {
  int s = q[point].size() - 1;
  if (point == 0) s = q[0].size();
  double ans = 0.0;
  if (s == 0 && point != 0) return len;
  while (!q[point].empty()) {
    int a = q[point].front();
    q[point].pop();
    if (a != parent) {
      ans += play(n, q, point, a, len + 1) * 1.0 / s;
    }
  }
  if (ans == 0) ans = 1;
  return ans;
}
int main() {
  int n;
  cin >> n;
  int a[6];
  a[0] = n % 10;
  n /= 10;
  a[1] = n % 10;
  n /= 10;
  a[2] = n % 10;
  n /= 10;
  a[3] = n % 10;
  n /= 10;
  a[4] = n % 10;
  n /= 10;
  a[5] = n % 10;
  sort(a, a + 3);
  sort(a + 3, a + 6);
  int s1 = a[0] + a[1] + a[2];
  int s2 = a[3] + a[4] + a[5];
  int c = 0;
  if (s1 > s2) {
    a[3] = 9 - a[3];
    a[4] = 9 - a[4];
    a[5] = 9 - a[5];
    sort(a, a + 6);
    int d = s1 - s2;
    while (d > 0) {
      d -= a[5 - c];
      c++;
    }
  } else if (s2 > s1) {
    a[0] = 9 - a[0];
    a[1] = 9 - a[1];
    a[2] = 9 - a[2];
    sort(a, a + 6);
    int d = -s1 + s2;
    while (d > 0) {
      d -= a[5 - c];
      c++;
    }
  }
  cout << c;
  return 0;
}
