#include <bits/stdc++.h>
using namespace std;
const int N = 210, INF = 1e9 + 7;
string s1, s2, s;
int main() {
  for (int i = 0; i < 3; ++i) {
    char x;
    cin >> x;
    s1 += x;
  }
  for (int i = 0; i < 3; ++i) {
    char x;
    cin >> x;
    s2 += x;
  }
  sort(s1.begin(), s1.end());
  sort(s2.begin(), s2.end());
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') ==
      int(s2[0] + s2[1] + s2[2] - 3 * '0'))
    return cout << 0, 0;
  int v = abs(int(s1[0] + s1[1] + s1[2] - 3 * '0') -
              int(s2[0] + s2[1] + s2[2] - 3 * '0'));
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') >
      int(s2[0] + s2[1] + s2[2] - 3 * '0')) {
    if ((s1[2] - '0') >= v) return cout << 1, 0;
    if (9 - (s2[0] - '0') >= v) return cout << 1, 0;
  }
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') <
      int(s2[0] + s2[1] + s2[2] - 3 * '0')) {
    if (9 - (s1[0] - '0') >= v) return cout << 1, 0;
    if ((s2[2] - '0') >= v) return cout << 1, 0;
  }
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') >
      int(s2[0] + s2[1] + s2[2] - 3 * '0')) {
    if ((s1[2] + s1[1] - 2 * '0') >= v) return cout << 2, 0;
    if (18 - (s2[0] + s2[1] - 2 * '0') >= v) return cout << 2, 0;
  }
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') <
      int(s2[0] + s2[1] + s2[2] - 3 * '0')) {
    if (18 - (s1[0] + s1[1] - 2 * '0') >= v) return cout << 2, 0;
    if ((s2[2] + s2[1] - 2 * '0') >= v) return cout << 2, 0;
  }
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') >
      int(s2[0] + s2[1] + s2[2] - 3 * '0')) {
    if ((9 - (s2[0] - '0')) + (s1[2] - '0') >= v) return cout << 2, 0;
  }
  if (int(s1[0] + s1[1] + s1[2] - 3 * '0') <
      int(s2[0] + s2[1] + s2[2] - 3 * '0')) {
    if ((9 - (s1[0] - '0')) + (s2[2] - '0') >= v) return cout << 2, 0;
  }
  cout << 3;
}
