#include <bits/stdc++.h>
using namespace std;
void cass() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 10;
int n, a[N], res = 1e9, x[N];
string s;
void read() {
  cin >> s;
  n = 6;
  for (int i = 0; i < s.length(); ++i) a[i + 1] = s[i] - '0';
}
void cmp() {
  int sum1 = x[1] + x[2] + x[3];
  int sum2 = x[4] + x[5] + x[6];
  if (sum1 != sum2) return;
  int dem = 0;
  for (int i = 1; i <= n; ++i)
    if (a[i] != x[i]) dem++;
  res = min(res, dem);
}
void tried(int i) {
  for (int j = 0; j <= 9; ++j) {
    x[i] = j;
    if (i == n)
      cmp();
    else
      tried(i + 1);
  }
}
int main() {
  cass();
  read();
  tried(1);
  cout << res;
  return 0;
}
