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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

int len;
string a,b;

int rec(const string& s,int idx){
    if(idx==len) return 0;
    const int d=(b[idx]-s[idx]+10)%10;
    if(d==0) return rec(s,idx+1);
    int res=inf;
    rep(i,1,len-idx+1){
        string tmp=s;
        rep(j,idx,idx+i){
            tmp[j]='0'+(tmp[j]-'0'+d)%10;
        }
        res=min(res,rec(tmp,idx+1)+1);
    }
    return res;
}

void solve(){
    while(true){
        cin >> len; if(!len) break;
        cin >> a >> b;
        cout << rec(a,0) << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    solve();
    return 0;
}