#include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 9223372036854775807;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline void randomizer3000() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
int a[6], b[6];
int ans = MX;
void relax() {
  int dif = 0, sum = 0;
  for (int i = 0; i < 6; i++) {
    if (a[i] != b[i]) dif++;
    if (i < 3)
      sum += b[i];
    else
      sum -= b[i];
  }
  if (!sum) ans = min(ans, dif);
}
void rec(int pos) {
  if (pos == 6) {
    relax();
    return;
  }
  for (int i = 0; i < 10; i++) {
    b[pos] = i;
    rec(pos + 1);
  }
}
int main() {
  Read_rap();
  for (int i = 0; i < 6; i++) {
    char c;
    cin >> c;
    a[i] = c - '0';
  }
  rec(0);
  cout << ans;
  return 0;
}
