#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

string s,t;
int k;

map<string,int>m;

int main(){
  while(cin >> k, k){
    cin >>s >> t;

    m.clear();
    queue<string>q;
    m[s] = 0;
    q.push(s);

    while(!q.empty()){
      string cur = q.front(); q.pop();
      int cnt = m[cur];
      //      cout << cur << endl;
      if(cur == t){
	printf("%d\n", cnt);
	break;
      }
      
      int p = 0;
      while(cur[p]- t[p] == 0 ) p++;
      int diff = (t[p]-'0') - (cur[p]-'0');
      for(;p<k;p++){
	int tmp = (int)(cur[p]-'0'+diff+10)%10;
	cur[p] = tmp+'0';
	if(m.find(cur) == m.end()){
	  q.push(cur);
	  m[cur] = cnt+1;
	}
      }
    }
  }
  return 0;
}