#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string str;
  cin >> str;
  vector<int> v;
  for (int i = 0; i < str.size(); i++) {
    int a = str[i] - '0';
    v.push_back(a);
  }
  int minn = 1000, cnt;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        for (int l = 0; l < 10; l++) {
          for (int m = 0; m < 10; m++) {
            for (int n = 0; n < 10; n++) {
              if (i + j + k == l + m + n) {
                cnt = 0;
                if (v[0] != i) cnt++;
                if (v[1] != j) cnt++;
                if (v[2] != k) cnt++;
                if (v[3] != l) cnt++;
                if (v[4] != m) cnt++;
                if (v[5] != n) cnt++;
                if (cnt < minn) minn = cnt;
              }
            }
          }
        }
      }
    }
  }
  cout << minn << endl;
  return 0;
}
