#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = ans * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return ans;
}
inline void getInt(int* p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
char a[maxn][8];
char s[maxn];
int main() {
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        for (int x = 0; x <= 9; x++) {
          for (int y = 0; y <= 9; y++) {
            for (int z = 0; z <= 9; z++) {
              a[i * 100000 + j * 10000 + k * 1000 + x * 100 + y * 10 + z][0] =
                  '0' + i;
              a[i * 100000 + j * 10000 + k * 1000 + x * 100 + y * 10 + z][1] =
                  '0' + j;
              a[i * 100000 + j * 10000 + k * 1000 + x * 100 + y * 10 + z][2] =
                  '0' + k;
              a[i * 100000 + j * 10000 + k * 1000 + x * 100 + y * 10 + z][3] =
                  '0' + x;
              a[i * 100000 + j * 10000 + k * 1000 + x * 100 + y * 10 + z][4] =
                  '0' + y;
              a[i * 100000 + j * 10000 + k * 1000 + x * 100 + y * 10 + z][5] =
                  '0' + z;
            }
          }
        }
      }
    }
  }
  cin >> s;
  int ans = inf;
  for (int i = 0; i <= 1000000; i++) {
    if (a[i][0] + a[i][1] + a[i][2] == a[i][3] + a[i][4] + a[i][5]) {
      int cnt = 0;
      for (int j = 0; j <= 5; j++) {
        if (a[i][j] != s[j]) {
          cnt++;
        }
      }
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}
inline void getInt(int* p) {
  char ch;
  do {
    ch = getchar();
  } while (ch == ' ' || ch == '\n');
  if (ch == '-') {
    *p = -(getchar() - '0');
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 - ch + '0';
    }
  } else {
    *p = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 + ch - '0';
    }
  }
}
