#include <bits/stdc++.h>
using namespace std;
int tab[10], f, s;
vector<int> a, b;
int main() {
  int l;
  scanf("%d", &l);
  for (int i = 1; i <= 6; i++) {
    tab[i] = l % 10;
    l /= 10;
    if (i < 4) {
      f += tab[i];
      a.push_back(tab[i]);
    } else {
      s += tab[i];
      b.push_back(tab[i]);
    }
  }
  int wyn = 0;
  while (s != f) {
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (f > s) {
      if (a[2] >= 9 - b[0]) {
        if (f - a[2] <= s) {
          a[2] = a[2] - f + s;
          f = s;
        } else {
          f -= a[2];
          a[2] = 0;
        }
      } else {
        if (s + (9 - b[0]) >= f) {
          b[0] += f - s;
          s = f;
        } else {
          s += (9 - b[0]);
          b[0] = 9;
        }
      }
    } else {
      if (b[2] >= 9 - a[0]) {
        if (s - b[2] <= f) {
          b[2] = b[2] - s + f;
          s = f;
        } else {
          s -= b[2];
          b[2] = 0;
        }
      } else {
        if (f + (9 - a[0]) >= s) {
          a[0] += s - f;
          f = s;
        } else {
          f += (9 - a[0]);
          a[0] = 9;
        }
      }
    }
    wyn++;
  }
  printf("%d", wyn);
  return 0;
}
