#include <bits/stdc++.h>
using namespace std;
string s;
int a[100010];
int main() {
  int i, j, k, l, m, n, ans = 1000, cnt = 0;
  cin >> s;
  for (i = 0; i <= 5; i++) a[i] = s[i] - '0';
  for (i = 0; i <= 9; i++)
    for (j = 0; j <= 9; j++)
      for (k = 0; k <= 9; k++)
        for (l = 0; l <= 9; l++)
          for (m = 0; m <= 9; m++)
            for (n = 0; n <= 9; n++) {
              if (i + j + k == l + m + n) {
                int cnt = 0;
                if (i != a[0]) cnt++;
                if (j != a[1]) cnt++;
                if (k != a[2]) cnt++;
                if (l != a[3]) cnt++;
                if (m != a[4]) cnt++;
                if (n != a[5]) cnt++;
                ans = min(ans, cnt);
              }
            }
  cout << ans << endl;
}
