#include <bits/stdc++.h>
using namespace std;
int main() {
  char num[7];
  scanf("%s", num);
  int i, data[6];
  for (i = 0; i < 6; i++) data[i] = num[i] - '0';
  sort(data, data + 3);
  sort(data + 3, data + 6);
  int left, right;
  left = data[0] + data[1] + data[2];
  right = data[3] + data[4] + data[5];
  if (left == right) printf("0");
  if (left < right) {
    if (left + 9 - data[0] >= right || right - data[5] <= left)
      printf("1");
    else if (left + 9 - data[0] >= right - data[5] ||
             left + 18 - data[0] - data[1] >= right ||
             left >= right - data[5] - data[4])
      printf("2");
    else
      printf("3");
  }
  if (left > right) {
    if (left - data[2] <= right || right + 9 - data[3] >= left)
      printf("1");
    else if (left - data[2] <= right + 9 - data[3] ||
             left - data[2] - data[1] <= right ||
             right + 18 - data[3] - data[4] >= left)
      printf("2");
    else
      printf("3");
  }
  return 0;
}
