#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
string S, T, U; queue<pair<string, int>>Q;
set<string>E;
int solve(string P, int n) {
	while (!Q.empty())Q.pop(); Q.push(make_pair(P, 0)); int CNT = 0; int maxn = 10;
	while (!Q.empty()) {
		string V = Q.front().first; int Z = Q.front().second; Q.pop(); int to = -1;
		for (int j = 0; j < n; j++)if (V[j] != '0') { to = j; break; }
		long long H = stoll(V);
		if (to == -1) { return Z; }
		int Y = (V[to] - '0'); int en = n - 1; CNT++;
		for (int j = to; j < n; j++)if (V[j] != V[to]) { en = j - 1; break; }

		for (int j = en; j < n; j++) {
			string W = V; int Y = (W[to] - '0');
			for (int k = to; k <= j; k++) {
				W[k] -= Y; if (W[k] < '0')W[k] += 10;
			}
			if (E.find(W) == E.end()) {
				Q.push(make_pair(W, Z + 1)); E.insert(W);
			}
		}
	}
}
int main() {
	while (true) {
		int n; cin >> n; E.clear(); if (n == 0)break; cin >> S >> T; U = "";
		for (int i = 0; i < n; i++) {
			int sa = T[i] - S[i]; if (sa < 0)sa += 10;
			U += (char)('0' + sa);
		}
		cout << solve(U, n) << endl;
	}
	return 0;
}