char s[maxn],t[maxn]; int dp[maxn][12][12]; int a[maxn],b[maxn]; intmain(){ while (~scanf("%s%s", s, t)){ for (int i = 0; i <= strlen(s); i ++) for (int j = 0; j < 10; j ++) for (int l = 0; l < 10; l ++) dp[i][j][l] = INF;
for (int i = 0; i < strlen(s); i++){ a[i+1] = s[i] - '0'; b[i+1] = t[i] - '0'; } int len = strlen(s); a[len + 1] = a[len + 2] = 0; b[len + 1] = b[len + 2] = 0;
dp[0][a[1]][a[2]] = 0;
for (int i = 1; i <= len; i ++){ for (int x = 0; x < 10; x++){ for (int y = 0; y < 10; y++){ int down = (x + 10 - b[i]) % 10; for (int k = 0; k <= down; k++) for (int l = 0; l <= k; l++){ dp[i][(y-k+10)%10][(a[i+2]-l+10)%10] = min(dp[i-1][x][y] + down, dp[i][(y-k+10)%10][(a[i+2]-l+10)%10]); } int up = 10 - down; for (int k = 0; k <= up; k++) for (int l = 0; l <= k; l++){ dp[i][(y+k)%10][(a[i+2]+l)%10] = min(dp[i-1][x][y] + up,dp[i][(y+k)%10][(a[i+2]+l)%10]); } } } } printf("%dn", dp[len][0][0]); } return0; }