#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

#define min(x , y) ((x) > (y) ? (y) : (x))
#define max(x , y) ((x) > (y) ? (x) : (y))
#define abs(x) ((x) > 0 ? (x) : -(x))


const int MAXN = 1010;
const int INF = MAXN * 10;
int n;
int dp[MAXN][10][10];
int a[MAXN], b[MAXN];
char s1[MAXN], s2[MAXN];

int dfs(int k, int i, int j){

    if(k == n){
//        printf("rt: %d  %d\n", i, j);
        if(i == b[n - 2] && j == b[n - 1])  return 0;
        return INF;
    }
    int &ret = dp[i][j][k];
    if(ret != -1)  {
//        printf("%d %d %d\n", k, i, j);
        return ret;
    }

    ret = INF;
    for(int u = 0; u < 2; ++u){

        int t1 = dfs(k, i, (j + u) % 10) + u;
        int t2 = dfs(k, i, (j - u + 10) % 10) + u;
        ret = min(t1, t2);

//        t1 = dfs(k, (i + u) % 10, (j + u) % 10) + u;
//        t2 = dfs(k, (i - u + 10) % 10, (j - u + 10) % 10 ) + u;
//        ret = min(ret, min(t1, t2));
//
//        t1 = dfs(k, (i + u) % 10, j) + u;
//        t2 = dfs(k, (i - u + 10) % 10, j) + u;
//        ret = min(ret, min(t1, t2));

    }

    if(i == b[k - 2]) {
        ret = dfs(k + 1, j, a[k]);
    }else{

//        int u = (b[k - 2] - i + 10) % 10;
//        int d = (i - b[k - 2] + 10) % 10;
//
//        ret = min(ret, dfs(k + 1, (j + u) % 10, (a[k] + u) % 10) + u);
//        ret = min(ret, dfs(k + 1, (j - d + 10) % 10, (a[k] - d + 10) % 10) + d);
    }

    printf("%d %d %d  %d  %d  \n", k, i, j, ret, b[k - 2]);
    return ret;
}



int main()
{

    freopen("C.in", "r", stdin);

    a[0] = b[0] = a[1] = b[1] = 0;
    while(~scanf("%s%s", s1 + 2, s2 + 2)){

//        printf("<%s  %s>\n", s1 + 2, s2 + 2);
        n = strlen(s1 + 2) + 2;
        for(int i = 2; i < n; ++i)
        {
            a[i] = s1[i] - '0';
            b[i] = s2[i] - '0';
//            printf("%d ", b[i]);
        }

        for(int i = 0; i <= n + 10; ++i)
        for(int j = 0; j < 10; ++j)
        for(int k = 0; k < 10; ++k)
            dp[i][j][k] = -1;
//        memset(dp, -1, sizeof(dp));
//        printf("n=%d\n", n);
        dfs(2, 0, 0);
        printf("%d\n", dfs(2, 0, 0));
    }

    return 0;
}