#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int l = 0;
  int r = 0;
  vector<int> a(3);
  vector<int> b(3);
  for (int i = 0; i < 3; i++) {
    a[i] = (int)(s[i] - '0');
    b[i] = (int)(s[i + 3] - '0');
    l += a[i];
    r += b[i];
  }
  if (l == r) {
    cout << "0";
    return 0;
  }
  int dif = abs(l - r);
  if (l > r) {
    sort(a.rbegin(), a.rend());
    sort(b.begin(), b.end());
    if (a[0] >= dif || (9 - b[0]) >= dif) {
      cout << "1";
      return 0;
    }
    int mx = max({a[0] + (9 - b[0]), a[0] + a[1], 18 - b[0] - b[1]});
    if (mx >= dif) {
      cout << "2";
      return 0;
    }
  } else {
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    if (b[0] >= dif || (9 - a[0]) >= dif) {
      cout << "1";
      return 0;
    }
    int mx = max({b[0] + (9 - a[0]), b[0] + b[1], 18 - a[0] - a[1]});
    if (mx >= dif) {
      cout << "2";
      return 0;
    }
  }
  cout << "3";
  return 0;
}
