#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int a[205];
int n;
char s[100];
char s1[50];
char s2[50];
int fuck(int i, int j, int k, int m, int n, int l) {
  int tmp = 0;
  if (i != s1[0] - '0') tmp++;
  if (j != s1[1] - '0') tmp++;
  if (k != s1[2] - '0') tmp++;
  if (m != s2[0] - '0') tmp++;
  if (n != s2[1] - '0') tmp++;
  if (l != s2[2] - '0') tmp++;
  return tmp;
}
int main() {
  while (~scanf("%s", s)) {
    int sum1 = 0;
    int sum2 = 0;
    for (int i = 0; i < 3; i++) {
      s1[i] = s[i];
    }
    for (int i = 3; i < 6; i++) {
      s2[i - 3] = s[i];
    }
    int ans = 0x3f3f3f3f;
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        for (int k = 0; k <= 9; k++) {
          for (int m = 0; m <= 9; m++) {
            for (int n = 0; n <= 9; n++) {
              for (int l = 0; l <= 9; l++) {
                if (i + j + k == m + n + l) {
                  ans = min(ans, fuck(i, j, k, m, n, l));
                }
              }
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
}
