#include <bits/stdc++.h>
using namespace std;
bool isValid(string& temp) {
  return ((temp[0] - '0') + (temp[1] - '0') + (temp[2] - '0')) ==
         ((temp[3] - '0') + (temp[4] - '0') + (temp[5] - '0'));
}
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  int mini = 3;
  if (isValid(s)) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 10; j++) {
        string temp = s;
        char c = (char)(j + '0');
        temp[i] = c;
        if (isValid(temp)) mini = min(mini, 1);
      }
    }
    for (int i = 0; i < 6; i++) {
      for (int j = i + 1; j < 6; j++) {
        for (int k = 0; k < 10; k++) {
          string temp = s;
          char c = (char)(k + '0');
          temp[i] = c;
          for (int l = 0; l < 10; l++) {
            char z = (char)(l + '0');
            temp[j] = z;
            if (isValid(temp)) mini = min(mini, 2);
          }
        }
      }
    }
    cout << mini << endl;
  }
  return 0;
}
