#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 10;
const long long BINF = 1e18 + 10;
const long long LINF = 1e18 + 10;
const long double EPS = 1e-10;
const long double PI = acos(-1);
inline void error() {
  cout << -1;
  exit(0);
}
string s;
vector<int> a(3), b(3);
inline void source() {
  cin >> s;
  a[0] = s[0] - '0';
  a[1] = s[1] - '0';
  a[2] = s[2] - '0';
  b[0] = s[3] - '0', b[1] = s[4] - '0', b[2] = s[5] - '0';
  if (a[0] + a[1] + a[2] == b[0] + b[1] + b[2]) {
    cout << 0;
    exit(0);
  }
  sort((a).begin(), (a).end());
  sort((b).begin(), (b).end());
  if (a[0] + a[1] + a[2] < b[0] + b[1] + b[2]) {
    swap(a, b);
  }
  if (a[0] + a[1] + a[2] - b[0] - b[1] - b[2] <= a[2] ||
      a[0] + a[1] + a[2] - b[0] - b[1] - b[2] <= 9 - b[0]) {
    cout << 1;
    exit(0);
  } else {
    if (a[0] + a[1] + a[2] - b[0] - b[1] - b[2] <= a[1] + a[2] ||
        a[0] + a[1] + a[2] - b[0] - b[1] - b[2] <= 9 - b[0] + 9 - b[1] ||
        a[0] + a[1] + a[2] - b[0] - b[1] - b[2] <= a[2] + 9 - b[0]) {
      cout << 2;
      exit(0);
    }
  }
  cout << 3;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  source();
  return 0;
}
