#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 30;
int N;
int a[10];

int dfs(int idx) {
  if (idx == N) return 0;
  int res = INF;
  if (a[idx] == 0) {
    res = min(res, dfs(idx + 1));
  } else {
    int tmp = a[idx];
    for (int i = 0; i < N - idx; i++) {
      for (int j = 0; j <= i; j++) {
        a[idx + j] = (a[idx + j] - tmp + 10) % 10;
      }
      res = min(res, dfs(idx + 1) + 1);
      for (int j = 0; j <= i; j++) {
        a[idx + j] = (a[idx + j] + tmp) % 10;
      }
    }
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> N, N) {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < N; i++) {
      a[i] = (t[i] - s[i] + 10) % 10;
    }
    cout << dfs(0) << endl;
  }  

  return 0;
}
