
const
	MaxN = 1000010;

var
        inFile, outFile : text;
	n, i, j, curr, sol : longint;
	m : array[0..12, 0..12] of longint;
	p : array[0..12] of longint;
	mark : array[0..12] of boolean;
        c : char;

procedure compareSolution;
begin
	curr := 0;
	for i := 0 to 9 do
		curr := curr + m[ p[i] ][i];

	if (curr < sol) then sol := curr;
end;

procedure permutations(k : longint);
var
	i : longint;
begin
	if (k >= 10) then compareSolution
	else
		for i := 0 to 9 do
			if (NOT mark[i]) then
			begin
				p[k] := i;
				mark[i] := true;
				permutations(k + 1);
				mark[i] := false;
			end;
end;

BEGIN

	assign(inFile, 'lepbroj.in');
	assign(outFile, 'lepbroj.out');
	reset(inFile); rewrite(outFile);

	fillchar(m, sizeof(m), 0);

	readln(inFile, n);
	for i := 1 to n do
	begin
		read(inFile, c);
		m[ord(c) - 48][i mod 10] := m[ord(c) - 48][i mod 10] + 1;
	end;

	for i := 0 to 9 do
		for j := 0 to 9 do
		begin
			m[i][j] := (n div 10) - m[i][j];
			if ((1 <= j + 1) and (j + 1 <= n mod 10)) then
				m[i][j] := m[i][j] + 1;
		end;

	sol := n + 1;
	fillchar(mark, sizeof(mark), false);
	permutations(0);

	writeln(outFile, sol);

	close(inFile);
	close(outFile);

END.
