#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 22, M = 98765431;
int n, res = 1e9;
string str;
void f(string cur = "") {
  if (cur.size() == 6) {
    int x = 0, y = 0, t = 0;
    for (int i = 0; i < (3); i++) x += cur[i] - '0', y += cur[i + 3] - '0';
    if (x == y) {
      for (int i = 0; i < (6); i++) t += cur[i] != str[i];
      res = min(res, t);
    }
    return;
  }
  for (int i = 0; i < (10); i++) f(cur + char('0' + i));
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  long long x, y;
  cin >> str;
  f();
  cout << res;
  return 0;
}
