#include <iostream>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

int n, ans;
string s, t;

void calc(int p, int cnt){
  if(ans <= cnt) return;
  if(p == n){
    ans = min(ans, cnt);
    return;
  }
  if(s[p] == t[p]) calc(p+1, cnt);
  int d = t[p] - s[p];
  for(int i=p;i<n;i++){
    for(int j=p;j<=i;j++) s[j] = ((s[j] - '0') + d + 10) % 10 + '0';
    calc(p+1, cnt+1);
    for(int j=p;j<=i;j++) s[j] = ((s[j] - '0') - d + 10) % 10 + '0';
  }
}

int main(){
  while(cin >> n && n){
    cin >> s >> t;
    ans = n;
    calc(0, 0);
    cout << ans << endl;
  }
}