Problem: A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened.

You are working at a manufacturer of dial locks. Your job is to verify that every manufactured lock is unlocked by its unlocking sequence. In other words, you have to rotate many dials of many many locks.

It’s a very hard and boring task. You want to reduce time to open the locks. It’s a good idea to rotate multiple dials at one time. It is, however, a difficult problem to find steps to open a given lock with the fewest rotations. So you decided to write a program to find such steps for given initial and unlocking sequences.

Your company’s dial locks are composed of vertically stacked k (1 ≤ k ≤ 10) cylindrical dials. Every dial has 10 numbers, from 0 to 9, along the side of the cylindrical shape from the left to the right in sequence. The neighbor on the right of 9 is 0.

A dial points one number at a certain position. If you rotate a dial to the left by i digits, the dial newly points the i-th right number. In contrast, if you rotate a dial to the right by i digits, it points the i-th left number. For example, if you rotate a dial pointing 8 to the left by 3 digits, the dial newly points 1.

You can rotate more than one adjacent dial at one time. For example, consider a lock with 5 dials. You can rotate just the 2nd dial. You can rotate the 3rd, 4th and 5th dials at the same time. But you cannot rotate the 1st and 3rd dials at one time without rotating the 2nd dial. When you rotate multiple dials, you have to rotate them to the same direction by the same digits.

Your program is to calculate the fewest number of rotations to unlock, for given initial and unlocking sequences. Rotating one or more adjacent dials to the same direction by the same digits is counted as one rotation.



Input

The input consists of multiple datasets. Each datset consists of two lines. The first line contains an integer k. The second lines contain two strings, separated by a space, which indicate the initial and unlocking sequences.

The last dataset is followed by a line containing one zero. This line is not a part of any dataset and should not be processed.

Output

For each dataset, print the minimum number of rotations in one line.

Example

Input

4
1357 4680
6
777777 003330
0


Output

1
2

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2157>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

class InitVal{
public:
    static bool INIT_B_VAL;
    static short INIT_SHRT_VAL;
    static unsigned short INIT_USHRT_VAL;
    static int INIT_I_VAL;
    static unsigned int INIT_UI_VAL;
    static long long INIT_LL_VAL;
    static unsigned long long INIT_ULL_VAL;
    static char INIT_C_VAL;
    static string INIT_STR_VAL;
    static float INIT_F_VAL;
    static double INIT_D_VAL;
    static long double INIT_LD_VAL;
    
    operator bool () {return INIT_B_VAL; }
    operator short () {return INIT_SHRT_VAL; }
    operator unsigned short () {return INIT_USHRT_VAL; }
    operator int () {return INIT_I_VAL; }
    operator unsigned int (){return INIT_UI_VAL; }
    operator long long () {return INIT_LL_VAL;}
    operator unsigned long long (){return INIT_ULL_VAL;}
    operator char () {return INIT_C_VAL; }
    operator string () {return INIT_STR_VAL; }
    operator float () {return INIT_F_VAL; }
    operator double () {return INIT_D_VAL; }
    operator long double (){return INIT_LD_VAL;}
    
    static void SetVal(bool _b){ INIT_B_VAL = _b;}
    static void SetVal(short _s){ INIT_STR_VAL = _s;}
    static void SetVal(unsigned short _us){INIT_USHRT_VAL = _us; }
    static void SetVal(int _i){ INIT_I_VAL = _i;}
    static void SetVal(unsigned int _ui){INIT_UI_VAL = _ui; }
    static void SetVal(long long _ll){ INIT_LL_VAL = _ll; }
    static void SetVal(unsigned long long _ull){INIT_ULL_VAL = _ull;}
    static void SetVal(char _c){INIT_C_VAL = _c;}
    static void SetVal(string _s){INIT_STR_VAL = _s;}
    static void SetVal(float _f){ INIT_F_VAL = _f;}
    static void SetVal(double _d){INIT_D_VAL = _d;}
    static void SetVal(long double _ld){ INIT_LD_VAL = _ld;}
};
bool InitVal::INIT_B_VAL = bool();
short InitVal::INIT_SHRT_VAL = short();
unsigned short InitVal::INIT_USHRT_VAL = ushort();
int InitVal::INIT_I_VAL = int();
unsigned int InitVal::INIT_UI_VAL = u_int();
long long InitVal::INIT_LL_VAL = int64_t();
unsigned long long InitVal::INIT_ULL_VAL = u_int64_t();
char InitVal::INIT_C_VAL = char();
string InitVal::INIT_STR_VAL = string();
float InitVal::INIT_F_VAL = float();
double InitVal::INIT_D_VAL = double();
long double InitVal::INIT_LD_VAL = static_cast<long double>(double()); //!! long_doubleデフォルトコンストラクタ名が分からん

template<typename T>
class InitMap:public InitVal{
public:
    T val;
    InitMap():val(InitVal()){}
    InitMap(T init):val(init){};
    static T GetInitVal(){ return InitVal(); }
    static void SetInitVal(T init){ InitVal::SetVal(init); }
    
    InitMap<T>& operator = (const T& o){ val = o; return (*this); }
    InitMap<T>& operator = (const InitMap<T>& o){ val = o.val; return (*this); }
    
    const InitMap<T> operator + (const T& o)const { return InitMap<T>(val+o);}
    const InitMap<T> operator + (const InitMap<T>& o) const{ return InitMap<T>(val+o.val);}
    const InitMap<T> operator - (const T& o)const { return InitMap<T>(val-o); }
    const InitMap<T> operator - (const InitMap<T>& o) const{ return InitMap<T>(val-o.val); }
    const InitMap<T> operator * (const T& o)const { return InitMap<T>(val*o);}
    const InitMap<T> operator * (const InitMap<T>& o) const{ return InitMap<T>(val*o.val); }
    const InitMap<T> operator / (const T& o)const { return InitMap<T>(val/o); }
    const InitMap<T> operator / (const InitMap<T>& o) const{ return InitMap<T>(val/o.val); }
    const InitMap<T> operator % (const T& o)const { return InitMap<T>(val%o); }
    const InitMap<T> operator % (const InitMap<T>& o) const{ return InitMap<T>(val%o.val); }
    
    InitMap<T>& operator += (const T& o){ val+=o; return (*this); }
    InitMap<T>& operator += (const InitMap<T>& o){ val+=o.val; return (*this); }
    InitMap<T>& operator -= (const T& o){val-=o; return (*this);}
    InitMap<T>& operator -= (const InitMap<T>& o){ val-=o.val; return (*this); }
    InitMap<T>& operator *= (const T& o){ val*=o; return (*this);}
    InitMap<T>& operator *= (const InitMap<T>& o){ val*=o.val; return (*this); }
    InitMap<T>& operator /= (const T& o){ val/=o; return (*this);}
    InitMap<T>& operator /= (const InitMap<T>& o){ val/=o.val; return (*this); }
    InitMap<T>& operator %= (const T& o){ val%=o; return (*this);}
    InitMap<T>& operator %= (const InitMap<T>& o){ val%=o.val; return (*this); }
    
    bool operator == (const T& o) const { return val == o; }
    bool operator == (const InitMap<T>& o) const { return val == o.val; }
    bool operator != (const T& o) const {return val!=o;}
    bool operator != (const InitMap<T>& o) const { return val != o.val; }
    bool operator < (const T& o) const { return val < o; }
    bool operator < (const InitMap<T>& o) const { return val < o.val; }
    bool operator <= (const T& o) const { return val <= o;}
    bool operator <= (const InitMap<T>& o) const { return val <= o.val; }
    bool operator > (const T& o) const {  return val > o;}
    bool operator > (const InitMap<T>& o) const { return val > o.val; }
    bool operator >= (const T& o) const { return val >= o;}
    bool operator >= (const InitMap<T>& o) const { return val == o.val; }
};
template<typename T> ostream& operator << (ostream& out,const InitMap<T>& o){ out << o.val; return out;}
template<typename T> istream& operator >> (istream& in, InitMap<T>& o){ in >> o.val; return in;}


ll solve(ll k){
    ll res = LINF;
    string S,T; cin >> S >> T;
    for(int i = 0; i < k;i++){ S[i] -= '0'; T[i] -= '0'; }
    InitMap<int>::SetInitVal(INT_MAX);
    
    queue<string> q;
    map<string,InitMap<int>> mp;
    
    mp[S] = 0;
    q.push(S);
    while(q.size()){
        string s = q.front(); q.pop();
        int dist = mp[s].val;
        if(s == T){
            res = dist;
            break;
        }
        
        int x = 0;
        while(s[x] == T[x]) x++;
        int diff = (T[x] - s[x] + 10)%10;
        for(int i = x; i < k;i++){
            (s[i] += diff)%=10;
            if(mp[s] > dist + 1){
                mp[s] = dist+1;
                q.push(s);
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll k;
    while(cin >> k,k){
        cout << solve(k) << endl;
    }
    return 0;
}