#include <bits/stdc++.h>
using namespace std;
int solve(string ch, int i) {
  if (i == 6) {
    if ((int)ch[0] + ch[1] + ch[2] == (int)ch[3] + ch[4] + ch[5])
      return 0;
    else
      return 1e5;
  }
  int ans = 1e5;
  for (char c = '0'; c <= '9'; ++c) {
    if (c == ch[i]) {
      ans = min(ans, solve(ch, i + 1));
      continue;
    }
    string ch1;
    ch1.resize(6);
    for (int ind = 0; ind < 6; ++ind) ch1[ind] = ch[ind];
    ch1[i] = c;
    ans = min(ans, 1 + solve(ch1, i + 1));
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string ch;
  cin >> ch;
  cout << solve(ch, 0);
  return 0;
}
