#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  char z[7];
  int x[7];
  int depan = 0, belakang = 0;
  int difp[7], difn[7];
  for (int i = 1; i <= 6; i++) {
    cin >> z[i];
    x[i] = z[i] - '0';
    difp[i] = x[i];
    difn[i] = 9 - x[i];
    if (i <= 3)
      depan += x[i];
    else
      belakang += x[i];
  }
  sort(difp + 1, difp + 4);
  sort(difp + 4, difp + 7);
  sort(difn + 1, difn + 4);
  sort(difn + 4, difn + 7);
  if (depan == belakang)
    cout << 0 << endl;
  else if (depan > belakang) {
    if (depan - difp[3] - belakang <= 0 || depan - (belakang + difn[6]) <= 0)
      cout << 1 << endl;
    else if (depan - difp[2] - difp[3] - belakang <= 0 ||
             depan - (belakang + difn[5] + difn[6]) <= 0 ||
             depan - difp[3] - (belakang + difn[6]) <= 0)
      cout << 2 << endl;
    else
      cout << 3 << endl;
  } else if (depan < belakang) {
    if (depan + difn[3] - belakang >= 0 || depan - (belakang - difp[6]) >= 0)
      cout << 1 << endl;
    else if (depan + difn[2] + difn[3] - belakang >= 0 ||
             depan - (belakang - difp[5] - difp[6]) >= 0 ||
             depan + difn[3] - (belakang - difp[6]) >= 0)
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
  return 0;
}
