#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int a[6];
int res = INF;
string s;
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  for (int i = 0; i < 1000000; i++) {
    for (int x = i, j = 0; j < 6; j++, x /= 10) a[j] = (x % 10);
    if (a[0] + a[1] + a[2] == a[3] + a[4] + a[5]) {
      int cost = 0;
      for (int j = 0; j < 6; j++) cost += (a[j] + '0' != s[j]);
      res = min(res, cost);
    }
  }
  cout << res << endl;
  return 0;
}
