#include <bits/stdc++.h>
using namespace std;
long long int prime(long long int n) {
  if (n % 2 == 0 && n != 2 || n < 2)
    return false;
  else {
    for (long long int i = 3; i * i <= n; i += 2) {
      if (n % i == 0) {
        return false;
      }
    }
  }
  return true;
}
unsigned long long gcd(unsigned long long n, unsigned long long m) {
  if (n % m == 0)
    return m;
  else
    return gcd(m, n % m);
}
long long int lcm(long long int n, long long int m) {
  return n * m / gcd(n, m);
}
long long int fact(long long int n) {
  if (n == 1)
    return 1;
  else
    return n * fact(n - 1);
}
int sumdigit(int n) {
  int sum = 0;
  while (n) {
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}
string tobinary(long long int n) {
  string s;
  while (n) {
    s += (n % 2) + '0';
    n /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
string tostring(double n) {
  double m = n;
  string x;
  stringstream ss;
  ss << m;
  ss >> x;
  return x;
}
char tochar(int n) {
  int m = n;
  char x;
  stringstream ss;
  ss << m;
  ss >> x;
  return x;
}
vector<long long int> v;
void div(long long int n) {
  for (long long int i = 2; i < int(sqrt(n)); i++) {
    if (n % i == 0) {
      v.push_back(i);
      v.push_back(n / i);
    }
  }
  if (int(sqrt(n)) * int(sqrt(n)) == n) v.push_back(sqrt(n));
}
int main() {
  int sum = 0, sum1 = 0, sub, c = 0, c1 = 0, c2;
  string s, x;
  cin >> s;
  x = s;
  for (int i = 0; i < 6; i++) {
    if (i <= 2)
      sum += s[i] - '0';
    else
      sum1 += s[i] - '0';
  }
  sub = abs(sum - sum1);
  if (sum > sum1) {
    sort(s.begin() + 3, s.begin() + 6);
    int i = 3;
    while (sub > 0) {
      sub -= (9 - (s[i] - '0'));
      i++;
      c++;
    }
  } else {
    sort(s.begin(), s.begin() + 3);
    int i = 0;
    while (sub > 0) {
      sub -= (9 - (s[i] - '0'));
      i++;
      c++;
    }
  }
  int mx, mn;
  sub = abs(sum - sum1);
  if (sum > sum1) {
    mx = max(s[0] - '0', s[1] - '0');
    mx = max(mx, s[2] - '0');
    mn = min(s[3] - '0', s[4] - '0');
    mn = min(mn, s[5] - '0');
    sort(s.rbegin() + 3, s.rbegin() + 6);
    int i = 0;
    while (sub > 0) {
      sub -= (s[i] - '0');
      i++;
      c1++;
    }
  } else {
    mn = min(s[0] - '0', s[1] - '0');
    mn = min(mn, s[2] - '0');
    mx = max(s[3] - '0', s[4] - '0');
    mx = max(mx, s[5] - '0');
    sort(s.rbegin(), s.rbegin() + 3);
    int i = 3;
    while (sub > 0) {
      sub -= (s[i] - '0');
      i++;
      c1++;
    }
  }
  if (abs(sum - sum1) - mx <= 9 - mn)
    c = min(c, 2), cout << min(c, c1);
  else
    cout << min(c, c1);
  return 0;
}
