#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  string s;
  cin >> s;
  vector<int> a, b;
  vector<int> dec1, dec2;
  int sum1 = s[0] - '0' + (s[1] - '0') + (s[2] - '0');
  int sum2 = (s[3] - '0') + (s[4] - '0') + (s[5] - '0');
  if (sum1 == sum2) {
    cout << 0 << endl;
    return 0;
  } else if (sum1 > sum2)
    for (int i = 0; i < 6; ++i) {
      if (i < 3)
        dec1.push_back((s[i] - '0'));
      else
        dec2.push_back(9 - (s[i] - '0'));
    }
  else {
    for (int i = 0; i < 6; ++i) {
      if (i < 3)
        dec1.push_back(9 - (s[i] - '0'));
      else
        dec2.push_back(s[i] - '0');
    }
  }
  sort(dec1.begin(), dec1.end());
  sort(dec2.begin(), dec2.end());
  int x = abs(sum1 - sum2);
  int cnt = 0, i = 2, j = 2;
  while (x > 0) {
    if (dec1[i] > dec2[j]) {
      x -= dec1[i];
      cnt++;
      i--;
    } else {
      x -= dec2[j];
      cnt++;
      j--;
    }
  }
  cout << cnt << endl;
  return 0;
}
