#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int solve(int d, string s) {
	if (d == n) return 0;
	if (s[d] == 48) return solve(d + 1, s);
	int ret = n;
	int e = s[d] - 48;
	for (int i = d + 1; i <= n; i++) {
		s[i - 1] = (s[i - 1] - 38 - e) % 10 + 48;
		ret = min(ret, solve(d + 1, s) + 1);
	}
	return ret;
}
int main() {
	string s, t;
	while (cin >> n, n) {
		cin >> s >> t;
		for (int i = 0; i < n; i++) s[i] = (t[i] - s[i] + 10) % 10 + 48;
		cout << solve(0, s) << endl;
	}
	return 0;
}