#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = tuple<int,int,int>;
const int inf = numeric_limits<int>::max()/3;

int state[15];
int dist[15];

int dfs(int now,int k){
  if(now == k)
    return 0;
  if(state[now] == dist[now]){
    return dfs(now+1,k);
  }
  int diff = (dist[now] - state[now] + 10) % 10;
  int res = inf;
  for(int i = now;i < k;++i){
    for(int j = now;j <= i;++j){
      state[j] = (state[j] + diff) % 10;
    }
    res = min(dfs(now+1,k)+1,res);
    for(int j = now;j <= i;++j){
      state[j] = (state[j] - diff + 10) % 10;
    }
  }
  return res;
}

void solve(int k){
  string s1,s2;
  cin >> s1 >> s2;
  for(int i = 0;i < k;++i)
    state[i] = s1[i] - '0';
  for(int i = 0;i < k;++i)
    dist[i] = s2[i] - '0';
  cout << dfs(0,k) << endl;
}

int main(void){
  int k;
  while(cin >> k,k)solve(k);
  return 0;
}