#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const string nl = "\n";
vector<char> a;
long long ans;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  a.resize(6);
  for (auto& i : a) {
    cin >> i;
    i -= '0';
  }
  long long hld = a[0] + a[1] + a[2] - a[3] - a[4] - a[5];
  if (hld < 0) {
    reverse(a.begin(), a.end());
    hld *= -1;
  }
  a[3] = 9 - a[3];
  a[4] = 9 - a[4];
  a[5] = 9 - a[5];
  sort(a.begin(), a.end());
  while (hld > 0) {
    ++ans;
    hld -= a[6 - ans];
  }
  cout << ans << nl;
}
