#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a[6];
  char c;
  for (int i = 0; i < 6; ++i) {
    cin >> c;
    a[i] = c - '0';
  }
  int sum_first = a[0] + a[1] + a[2], sum_second = a[3] + a[4] + a[5], qua = 0;
  if (sum_first > sum_second) {
    swap(sum_first, sum_second);
    swap(a[0], a[3]);
    swap(a[1], a[4]);
    swap(a[2], a[5]);
  }
  while (sum_first != sum_second) {
    ++qua;
    int max_change = 0, num_change = 0;
    for (int i = 0; i < 3; ++i) {
      if (9 - a[i] > max_change) {
        max_change = 9 - a[i];
        num_change = i;
      }
    }
    for (int i = 3; i < 6; ++i) {
      if (a[i] > max_change) {
        max_change = a[i];
        num_change = i;
      }
    }
    if (num_change < 3) {
      int change = min(sum_second - sum_first, max_change);
      a[num_change] += change;
      sum_first += change;
    } else {
      int change = min(sum_second - sum_first, max_change);
      a[num_change] -= change;
      sum_second -= change;
    }
  }
  cout << qua << '\n';
  return 0;
}
