#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef map<string,int> msi;

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int k;
    cin >> k;
    if (k == 0) break;

    string sstr, gstr;
    cin >> sstr >> gstr;

    msi dists;
    dists[sstr] = 0;

    queue<string> q;
    q.push(sstr);

    while (! q.empty()) {
      string u = q.front(); q.pop();

      int i;
      for (i = 0; i < k && u[i] == gstr[i]; i++);
      if (i == k) break;

      int ud = dists[u];
      int r = (gstr[i] - u[i] + 10) % 10;

      for (; i < k; i++) {
	u[i] = (((u[i] - '0') + r) % 10) + '0';
	if (dists.find(u) == dists.end()) {
	  dists[u] = ud + 1;
	  q.push(u);
	}
      }
    }

    cout << dists[gstr] << endl;
  }

  return 0;
}