// AOJ 2157: Dial Lock
// 2017.11.9 bal4u@uu

#include <stdio.h>
#include <string.h>

#define QSIZE 5000000
typedef struct { char s[10]; int k; } Q;
Q q[QSIZE+2]; int top, end;

int main()
{
	int n, i, k, d, ans;
	char s[11], t[11], *p;

	while (scanf("%d", &n) && n > 0) {
		scanf("%s%s", s, t);
		p = s; while (*p) *p++ -= '0';
		p = t; while (*p) *p++ -= '0';
		memcpy(q[0].s, s, n), q[0].k = 0; top = 0, end = 1;
		ans = -1;
		while (top != end) {
			memcpy(s, q[top].s, n), k = q[top].k; if (++top == QSIZE) top = 0;
			if (!memcmp(s, t, n)) { ans = k; break; }
			for (i = 0; s[i] == t[i]; i++);
			d = t[i] - s[i]; if (d < 0) d += 10;
			for ( ; i < n; i++) {
				s[i] += d; if (s[i] >= 10) s[i] -= 10;
				memcpy(q[end].s, s, n), q[end].k = k+1; if (++end == QSIZE) end = 0;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}