#include <bits/stdc++.h>
using namespace std;
int a1[200005];
long long dfs(string s, int i) {
  if (s[0] - '0' + s[1] - '0' + s[2] - '0' ==
      s[3] - '0' + s[4] - '0' + s[5] - '0')
    return 0;
  if (s.length() == i) return 1000000000;
  long long mx = 10000000000000;
  char t = s[i];
  for (int j = 0; j <= 9; j++) {
    s[i] = '0' + j;
    int c = ('0' + j != t);
    mx = min(dfs(s, i + 1) + c, mx);
  }
  return mx;
}
int main() {
  string s;
  cin >> s;
  cout << dfs(s, 0);
}
