#include <bits/stdc++.h>
int main() {
  char Ticket[6];
  int First, Second, i, Max1 = 0, Min1 = 10, Max2 = 0, Min2 = 10, tst1, tst2,
                        Index[6 - 2], Mid1, Mid2;
  gets(Ticket);
  for (i = 0; i < 6; i++) {
    Ticket[i] -= 48;
    if (i < 3 && Ticket[i] > Max1) {
      Max1 = Ticket[i];
      Index[0] = i;
    }
    if (i > 2 && Ticket[i] > Max2) {
      Max2 = Ticket[i];
      Index[2] = i;
    }
    if (i < 3 && Ticket[i] < Min1) {
      Min1 = Ticket[i];
      Index[1] = i;
    }
    if (i > 2 && Ticket[i] < Min2) {
      Min2 = Ticket[i];
      Index[3] = i;
    }
  }
  for (i = 0; i < 6; i++) {
    if (i < 3 && Index[0] != i && Index[1] != i) {
      Mid1 = Ticket[i];
    }
    if (i > 2 && Index[2] != i && Index[3] != i) {
      Mid2 = Ticket[i];
    }
  }
  First = Ticket[0] + Ticket[1] + Ticket[2];
  Second = Ticket[3] + Ticket[4] + Ticket[5];
  if (First == Second) {
    printf("0");
  } else {
    if (First < Second) {
      tst1 = First + 9 - Min1;
      tst2 = Second - Max2;
      if (tst2 <= First || tst1 >= Second) {
        printf("1");
      } else if (tst1 >= tst2 || tst2 - Mid2 <= First ||
                 tst1 - Mid1 + 9 >= Second) {
        printf("2");
      } else {
        printf("3");
      }
    } else {
      tst1 = First - Max1;
      tst2 = Second + 9 - Min2;
      if (tst2 >= First || tst1 <= Second) {
        printf("1");
      } else if (tst1 <= tst2 || tst1 - Mid1 <= Second ||
                 tst2 - Mid2 + 9 >= First) {
        printf("2");
      } else {
        printf("3");
      }
    }
  }
  return 0;
}
