#include <bits/stdc++.h>
using namespace std;
string s;
vector<vector<int> > a[28];
vector<int> t, v1, v2;
int ans = 1e9;
void gen(int ind) {
  if (ind == 3) {
    a[t[0] + t[1] + t[2]].push_back(t);
    return;
  }
  for (int i = 0; i <= 9; i++) {
    t.push_back(i);
    gen(ind + 1);
    t.pop_back();
  }
}
int dif(vector<int> aa, vector<int> bb) {
  int ret = 0;
  for (int i = 0; i < aa.size(); i++) ret += (aa[i] != bb[i]);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  v1.push_back(s[0] - '0');
  v1.push_back(s[1] - '0');
  v1.push_back(s[2] - '0');
  v2.push_back(s[3] - '0');
  v2.push_back(s[4] - '0');
  v2.push_back(s[5] - '0');
  gen(0);
  for (int i = 0; i <= 27; i++)
    for (int j = 0; j < a[i].size(); j++)
      for (int k = 0; k < a[i].size(); k++)
        ans = min(ans, dif(v1, a[i][j]) + dif(v2, a[i][k]));
  cout << ans << endl;
  return 0;
}
