#include <bits/stdc++.h>
using namespace std;
string s;
int dp[7][30][30];
int f(int i, int s1, int s2) {
  if (i == 6) {
    if (s1 == s2) return 0;
    return 100;
  }
  if (dp[i][s1][s2] != -1) return dp[i][s1][s2];
  int r1;
  if (i < 3) {
    r1 = f(i + 1, s1 + s[i] - '0', s2);
    for (int j = 0; j < 10; j++) {
      r1 = min(r1, f(i + 1, s1 + j, s2) + 1);
    }
  } else {
    r1 = f(i + 1, s1, s2 + s[i] - '0');
    for (int j = 0; j < 10; j++) {
      r1 = min(r1, f(i + 1, s1, s2 + j) + 1);
    }
  }
  return dp[i][s1][s2] = r1;
}
int main() {
  ios::sync_with_stdio(0);
  memset(dp, -1, sizeof dp);
  cin >> s;
  cout << f(0, 0, 0) << endl;
  return 0;
}
