#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
  long long x = a + b;
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ans;
}
int sum1, sum2;
int v[9];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (int i = 1; i <= 6; ++i) {
    char c;
    cin >> c;
    v[i - 1] = (c - '0');
  }
  int ans = 7;
  for (int i = 0; i < (1 << 6); ++i) {
    sum1 = sum2 = 0;
    int pot = 0;
    int pot2 = 0;
    for (int j = 0; j <= 2; ++j) {
      if (i & (1 << j))
        ++pot;
      else
        sum1 += v[j];
    }
    for (int j = 3; j <= 5; ++j) {
      if (i & (1 << j))
        ++pot2;
      else
        sum2 += v[j];
    }
    if (sum1 <= sum2) {
      if (sum2 - sum1 <= 9 * pot) ans = min(ans, pot + pot2);
    } else {
      if (sum1 - sum2 <= 9 * pot2) ans = min(ans, pot + pot2);
    }
  }
  cout << ans;
  return 0;
}
