#include <bits/stdc++.h>
using namespace std;
template <class T>
T power(T a, T b) {
  T x;
  if (b == 0)
    x = 1;
  else
    x = a;
  for (size_t i = 1; i < b; i++) x *= a;
  return x;
}
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int n, m, a, b, c, ab, ba, x, y, z, avg, sum;
int arr3[200001], arr4[200001], arr5[100001];
bool f, f1, f2;
string str, s1, s2, s3, s4;
set<int> seto;
double d, d1;
long long int x1, x2, y11, y2;
int mini = 1 << 30, maxi = 0;
int arr2[100001], dp[5001];
int main() {
  cin >> str;
  s1 = str.substr(0, 3);
  s2 = str.substr(3);
  for (int i = 0; i < 3; i++) y += s2[i] - '0';
  for (int i = 0; i < 3; i++) x += s1[i] - '0';
  if (x > y) {
    swap(x, y);
    swap(s1, s2);
  }
  while (x < y) {
    int mx1, mx2;
    mx1 = mx2 = 0;
    for (int i = 0; i < 3; i++) {
      if ('9' - s1[i] > mx1) mx1 = '9' - s1[i], a = i;
    }
    for (int i = 0; i < 3; i++) {
      if (s2[i] - '0' > mx2) mx2 = s2[i] - '0', b = i;
    }
    z++;
    if (max(mx1, mx2) >= y - x) {
      x = y;
      break;
    } else {
      if (mx1 > mx2)
        s1[a] = '9', x += mx1;
      else
        s2[b] = '0', y -= mx2;
    }
  }
  cout << z;
}
