#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int a[7];
  for (int i = 0; i < 6; i++) {
    a[i] = s[i] - '0';
  }
  int ans = 3;
  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++) {
              if (i + j + k == x + y + z) {
                int res = 0;
                if (i != a[0]) res++;
                if (j != a[1]) res++;
                if (k != a[2]) res++;
                if (x != a[3]) res++;
                if (y != a[4]) res++;
                if (z != a[5]) res++;
                ans = min(ans, res);
              }
            }
          }
        }
      }
    }
  }
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 9; k++) {
        if (i + j + k == a[3] + a[4] + a[5]) {
          int res = 0;
          if (i != a[0]) res++;
          if (j != a[1]) res++;
          if (k != a[2]) res++;
          ans = min(ans, res);
        }
      }
    }
  }
  cout << ans << '\n';
}
