#include <bits/stdc++.h>
using namespace std;
int main() {
  string st;
  cin >> st;
  int ans = 7;
  for (int i = 0; i <= 999999; i++) {
    int arr[6];
    int x = i;
    for (int j = 0; j < 6; j++) {
      arr[j] = x % 10;
      x = x / 10;
    }
    if (arr[0] + arr[1] + arr[2] == arr[3] + arr[4] + arr[5]) {
      int gg = 0;
      for (int k = 0; k < 6; k++) {
        if (arr[k] != st[k] - '0') gg++;
      }
      ans = min(gg, ans);
    }
  }
  cout << ans;
  return 0;
}
