#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>
using namespace std;
int getMin(vector v)
{
int minVal = INT_MAX;
for (auto e : v)
minVal = min(e, minVal);
return minVal;
}
int calc(vector v1, vector v2)
{
int sum1 = accumulate(v1.begin(), v1.end(), 0);
int sum2 = accumulate(v2.begin(), v2.end(), 0);
if (sum1 > sum2)
{
swap(v1, v2);
swap(sum1, sum2);
}
int diff = sum2 - sum1;
int ret = 0;
if (diff == 0)
return ret;
else
{
while (diff > 0)
{
int tmp = 9 - getMin(v1);
auto it = find(v1.begin(), v1.end(), getMin(v1));
*it = 9;
diff -= tmp;
++ret;
}
}
return ret;
}
int main(int argc, char const *argv[])
{
string str;
cin >> str;
vector v;
for (auto s : str)
v.emplace_back(s - '0');
vector v1(v.begin(), v.begin() + 3);
vector v2(v.begin() + 3, v.end());
int res = calc(v1, v2);
cout << res << endl;
return 0;
}