#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 2e5 + 5;
const long long limit1 = 1e6 + 5;
const long long limit2 = 1e3 + 5;
string s;
string s1, s2;
long long a[limit];
bool check[limit];
long long ans = maxN;
long long t2, t3, t, t1;
bool ok = false;
void process() {
  t = t2, t1 = t3;
  for (int i = (1); i <= (6); ++i) {
    if (a[i] == 1) {
      if (i <= 3 && ok)
        t += 9 - s[i - 1] + '0';
      else if (i > 3 && ok)
        t1 -= s[i - 1] - '0';
      if (i <= 3 && !ok)
        t -= s[i - 1] - '0';
      else if (i > 3 && !ok)
        t1 += 9 - s[i - 1] + '0';
      if ((t >= t1 && ok) || (t <= t1 && !ok)) {
        ans = min(ans, 1LL);
        return;
      } else
        for (int j = (1); j <= (6); ++j) {
          if (a[j] == 2) {
            if (j <= 3 && ok)
              t += 9 - s[j - 1] + '0';
            else if (j > 3 && ok)
              t1 -= s[j - 1] - '0';
            if (j <= 3 && !ok)
              t -= s[j - 1] - '0';
            else if (j > 3 && !ok)
              t1 += 9 - s[j - 1] + '0';
            if ((t >= t1 && ok) || (t <= t1 && !ok)) {
              ans = min(ans, 2LL);
              return;
            } else
              for (int k = (1); k <= (6); ++k) {
                if (a[k] == 3) {
                  if (k <= 3 && ok)
                    t += 9 - s[k - 1] + '0';
                  else if (k > 3 && ok)
                    t1 -= s[k - 1] - '0';
                  if (k <= 3 && !ok)
                    t -= s[k - 1] - '0';
                  else if (k > 3 && !ok)
                    t1 += 9 - s[k - 1] + '0';
                  if ((t >= t1 && ok) || (t <= t1 && !ok)) {
                    ans = min(ans, 3LL);
                    return;
                  }
                }
              }
          }
        }
    }
  }
  for (int i = (1); i <= (6); ++i) {
    if (a[i] == 4) {
      if (i <= 3 && ok)
        t += 9 - s[i - 1] + '0';
      else if (i > 3 && ok)
        t1 -= s[i - 1] - '0';
      if (i <= 3 && !ok)
        t -= s[i - 1] - '0';
      else if (i > 3 && !ok)
        t1 += 9 - s[i - 1] + '0';
      if ((t >= t1 && ok) || (t <= t1 && !ok)) {
        ans = min(ans, 4LL);
        return;
      } else
        for (int j = (1); j <= (6); ++j) {
          if (a[j] == 5) {
            if (j <= 3 && ok)
              t += 9 - s[j - 1] + '0';
            else if (j > 3 && ok)
              t1 -= s[j - 1] - '0';
            if (j <= 3 && !ok)
              t -= s[j - 1] - '0';
            else if (j > 3 && !ok)
              t1 += 9 - s[j - 1] + '0';
            if ((t >= t1 && ok) || (t <= t1 && !ok)) {
              ans = min(ans, 5LL);
              return;
            } else
              for (int k = (1); k <= (6); ++k) {
                if (a[k] == 6) {
                  if (k <= 3 && ok)
                    t += 9 - s[k - 1] + '0';
                  else if (k > 3 && ok)
                    t1 -= s[k - 1] - '0';
                  if (k <= 3 && !ok)
                    t -= s[k - 1] - '0';
                  else if (k > 3 && !ok)
                    t1 += 9 - s[k - 1] + '0';
                  if ((t >= t1 && ok) || (t <= t1 && !ok)) {
                    ans = min(ans, 6LL);
                    return;
                  }
                }
              }
          }
        }
    }
  }
}
void backtrack(long long i) {
  for (int j = (1); j <= (6); ++j) {
    if (!check[j]) {
      a[i] = j;
      check[j] = true;
      if (i == 6)
        process();
      else
        backtrack(i + 1);
      check[j] = false;
    }
  }
}
void solveProblem() {
  t = s[0] - '0' + s[1] - '0' + s[2] - '0';
  t1 = s[3] - '0' + s[4] - '0' + s[5] - '0';
  s1 = "", s2 = "";
  for (int i = (0); i < (3); ++i) s1 += s[i], s2 += s[i + 3];
  if (t == t1) {
    cout << 0 << '\n';
    return;
  }
  if (t < t1) ok = true;
  t2 = t, t3 = t1;
  backtrack(1);
  cout << ans << '\n';
}
void fastInput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void readInput() { cin >> s; }
int main() {
  fastInput();
  readInput();
  solveProblem();
}
