#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;


int main(){
	
	while(true){
		int n;
		cin >> n;
		if(n == 0){
			break;
		}
		
		vector<int> v;
		
		string str1, str2;
		cin >> str1 >> str2;
		
		int num = (str1[0] - str2[0] + 10) % 10;
		if(num != 0){
			v.push_back(num);
		}
		
		for(int i = 1; i < n; i++){
			int d1 = str1[i] - str1[i - 1];
			int d2 = str2[i] - str2[i - 1];
			num = (d1 - d2 + 100) % 10;
			if(num != 0){
				v.push_back(num);
			}
		}
		
		num = (str2[n - 1] - str1[n - 1] + 10) % 10;
		if(num != 0){
			v.push_back(num);
		}
		
		sort(v.begin(), v.end());
		
		int ans = 10000;
		
		do{
			int cnt = 0;
			int pre = 0;
			int S = 0;
			for(int i = 0; i < v.size(); i++){
				S += v[i];
				if(S % 10 == 0){
					cnt += i - pre;
					pre = i + 1;
				}
				//cout << v[i] << " ";
			}
			//cout << endl;
			ans = min(ans, cnt);
		}while(next_permutation(v.begin(), v.end()));
		
		cout << ans << endl;
	}
	
	return 0;
}

