#include <bits/stdc++.h>
using namespace std;


int bfs(string& S, string& T)
{
  queue< string > que;
  map< string, int > v;
  que.push(S);
  v[S] = 0;
  while(!que.empty()) {
    string& p = que.front();
    int now = v[p];
    if(p == T) return(now);
    int match = 0;
    while(p[match] == T[match]) ++match;
    int ptrr = (T[match] - p[match] + 10) % 10;
    for(int j = match; j < p.size(); j++) {
      (p[j] += ptrr) %= 10;
      if(v.find(p) == v.end()) {
        v[p] = now + 1;
        que.push(p);
      }
    }
    que.pop();
  }
}
int main()
{
  int K;
  while(cin >> K, K) {
    string S, T;
    cin >> S >> T;
    for(int i = 0; i < K; i++) {
      S[i] -= '0';
      T[i] -= '0';
    }
    cout << bfs(S, T) << endl;
  }
}