#include <bits/stdc++.h>
using namespace std;
string str, str1, str2;
int sum1;
int sum2;
int n1, n2;
int minn, maxx;
int pos1, pos2;
void recountSmall() {
  for (int i = 0; i < 3; i++) {
    if (str1[i] - '0' < minn) {
      minn = str1[i] - '0';
      pos1 = i;
    }
  }
}
void recountBig() {
  for (int i = 0; i < 3; i++) {
    if (str2[i] - '0' > maxx) {
      maxx = str2[i] - '0';
      pos2 = i;
    }
  }
}
int main() {
  cin >> str;
  str1 = str.substr(0, 3);
  str2 = str.substr(3, 3);
  for (int i = 0; i < 3; i++) {
    sum1 += str[i] - '0';
    n1 += pow(10, 2 - i) * (str[i] - '0');
  }
  for (int i = 3; i < 6; i++) {
    sum2 += str[i] - '0';
    n2 += pow(10, 5 - i) * (str[i] - '0');
  }
  if (sum1 > sum2) {
    swap(sum1, sum2);
    swap(n1, n2);
    swap(str1, str2);
  }
  int count = 0;
  int remain = sum2 - sum1;
  while (remain != 0) {
    count++;
    minn = 9;
    maxx = 0;
    recountBig();
    recountSmall();
    if (9 - minn > maxx) {
      if (remain > 9 - minn) {
        str1[pos1] = '9';
        remain -= 9 - minn;
        recountBig();
        recountSmall();
      } else {
        break;
      }
    } else {
      if (remain > maxx) {
        str2[pos2] = '0';
        remain -= maxx;
        recountBig();
        recountSmall();
      } else {
        break;
      }
    }
  }
  cout << count;
  return 0;
}
