#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int solve(string s, string t)
{
	if (s == t) return 0;
	int p = INF;
	REP(i, s.size())
	{
		if (s[i] != t[i])
		{
			chmin(p, i);
		}
	}
	int r = t[p] - s[p];
	int res = INF;
	FOR(i, 1, s.size() - p + 1)
	{
		string u = s;
		REP(j, i)
		{
			u[p + j] += r;
			if (u[p + j] > '9') u[p + j] -= 10;
			if (u[p + j] < '0') u[p + j] += 10;
		}
		chmin(res, solve(u, t) + 1);
	}
	return res;
}

int main()
{
	int n;
	while (cin >> n, n)
	{
		string s, t; cin >> s >> t;
		cout << solve(s, t) << endl;
	}
	return 0;
}