#include <bits/stdc++.h>
using namespace std;
bool IsLucky(int x) {
  int a = 0, b = 0;
  for (int i = 0; i < 3; ++i) {
    a += x % 10;
    x /= 10;
  }
  for (int i = 0; i < 3; ++i) {
    b += x % 10;
    x /= 10;
  }
  return a == b;
}
int CountDifference(int a, int b) {
  int ans = 0;
  for (int i = 0; i < 6; ++i) {
    ans += (a % 10) != (b % 10);
    a /= 10, b /= 10;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  int ans = 6;
  for (int i = 0; i <= 999999; ++i) {
    if (IsLucky(i)) {
      ans = min(ans, CountDifference(n, i));
    }
  }
  cout << ans;
}
