// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio     : readln, writeln;
import std.string    : chomp;
import std.array     : split;
import std.conv      : to;
import std.algorithm : sum;

auto gets() { return readln.chomp; }
auto getNum(T)() { return gets.to!T; }
auto getVals(T)() { return gets.split.to!(T[]); }

void main() {
    auto n = getNum!int;
    int[6] xs;
    for (int i = 0; i < 6; i++) {
        xs[i] = n % 10;
        n = (n - n % 10) / 10;
    }
    auto check = () => sum(xs[0..3]) == sum(xs[3..$]);
    if (check()) {
        writeln(0);
        return;
    }
    foreach (i; 0..6) {
        auto backup = xs[i];
        foreach (j; 0..10) {
            xs[i] = j;
            if (check()) {
                writeln(1);
                return;
            }
        }
        xs[i] = backup;
    }
    foreach (i; 0..5) {
        auto backupA = xs[i];
        foreach (a; 0..10) {
            xs[i] = a;
            foreach (j; i+1..6) {
                auto backupB = xs[j];
                foreach (b; 0..10) {
                    xs[j] = b;
                    if (check()) {
                        writeln(2);
                        return;
                    }
                }
                xs[j] = backupB;
            }
        }
        xs[i] = backupA;
    }
    writeln(3);
}