#include <bits/stdc++.h>
using namespace std;
char s[6];
int d[10];
int main() {
  int i, j, x, ans, cnt;
  cin >> s;
  ans = 3;
  for (i = 0; i <= 999999; i++) {
    x = i;
    for (j = 5; j >= 0; j--) {
      d[j] = x % 10;
      x /= 10;
    }
    if (d[0] + d[1] + d[2] == d[3] + d[4] + d[5]) {
      cnt = 0;
      for (j = 0; j < 6; j++)
        if ((s[j] - 48) != d[j]) cnt++;
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}
