#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
  int n, m;
  string s1;
  cin >> s1;
  int sum = s1[0] - '0' + s1[1] - '0' + s1[2] - '0';
  int sum2 = s1[3] - '0' + s1[4] - '0' + s1[5] - '0';
  int c1 = s1[0] - '0';
  int c2 = s1[1] - '0';
  int c3 = s1[2] - '0';
  int c4 = s1[3] - '0';
  int c5 = s1[4] - '0';
  int c6 = s1[5] - '0';
  if (sum2 == sum) {
    cout << 0;
    return 0;
  }
  if (sum2 > sum) {
    int k = min(c1, min(c2, c3));
    int k2 = max(c4, max(c5, c6));
    if (sum2 - sum <= 9 - k) {
      cout << 1;
      return 0;
    }
    if (sum2 - sum <= k2) {
      cout << 1;
      return 0;
    }
    if (9 - k > k2) {
      if (c1 == k)
        c1 = 9;
      else if (c2 == k)
        c2 = 9;
      else if (c3 == k)
        c3 = 9;
      sum = c1 + c2 + c3;
    } else {
      if (c4 == k2)
        c4 = 0;
      else if (c5 == k2)
        c5 = 0;
      else if (c6 == k2)
        c6 = 0;
      sum2 = c4 + c5 + c6;
    }
    k = min(c1, min(c2, c3));
    k2 = max(c4, max(c5, c6));
    if (sum2 - sum <= 9 - k) {
      cout << 2;
      return 0;
    }
    if (sum2 - sum <= k2) {
      cout << 2;
      return 0;
    }
    if (9 - k > k2) {
      if (c1 == k)
        c1 = 9;
      else if (c2 == k)
        c2 = 9;
      else if (c3 == k)
        c3 = 9;
      sum = c1 + c2 + c3;
    } else {
      if (c4 == k2)
        c4 = 0;
      else if (c5 == k2)
        c5 = 0;
      else if (c6 == k2)
        c6 = 0;
      sum2 = c4 + c5 + c6;
    }
    cout << 3;
  } else {
    int k = max(c1, max(c2, c3));
    int k2 = min(c4, min(c5, c6));
    if (sum - sum2 <= k) {
      cout << 1;
      return 0;
    }
    if (sum - sum2 <= 9 - k2) {
      cout << 1;
      return 0;
    }
    if (k > 9 - k2) {
      if (c1 == k)
        c1 = 0;
      else if (c2 == k)
        c2 = 0;
      else if (c3 == k)
        c3 = 0;
      sum = c1 + c2 + c3;
    } else {
      if (c4 == k2)
        c4 = 9;
      else if (c5 == k2)
        c5 = 9;
      else if (c6 == k2)
        c6 = 9;
      sum2 = c4 + c5 + c6;
    }
    k = max(c1, max(c2, c3));
    k2 = min(c4, min(c5, c6));
    if (sum - sum2 <= k) {
      cout << 2;
      return 0;
    }
    if (sum - sum2 <= 9 - k2) {
      cout << 2;
      return 0;
    }
    if (k > 9 - k2) {
      if (c1 == k)
        c1 = 0;
      else if (c2 == k)
        c2 = 0;
      else if (c3 == k)
        c3 = 0;
      sum = c1 + c2 + c3;
    } else {
      if (c4 == k2)
        c4 = 9;
      else if (c5 == k2)
        c5 = 9;
      else if (c6 == k2)
        c6 = 9;
      sum2 = c4 + c5 + c6;
    }
    cout << 3;
  }
}
