#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string s1 = s.substr(0, 3);
  string s2 = s.substr(3);
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  int a1 = (int)(s1[0] - '0') + (int)(s1[1] - '0') + (int)(s1[2] - '0');
  int a2 = (int)(s2[0] - '0') + (int)(s2[1] - '0') + (int)(s2[2] - '0');
  if (a1 == a2) {
    cout << 0;
    return 0;
  }
  if (a1 > a2) {
    swap(a1, a2);
    swap(s1, s2);
  }
  int cnt = 0;
  int i = 0, j = 2;
  while ((a1 < a2) && (i < 3) && (j > -1)) {
    if ((int)('9' - s1[i]) >= (int)(s2[j] - '0')) {
      a1 += (int)('9' - s1[i]);
      i++;
    } else {
      a2 -= (int)(s2[j] - '0');
      j--;
    }
    cnt++;
  }
  cout << cnt;
}
