#include <bits/stdc++.h>
using namespace std;
int arr[5], vis[10];
int main() {
  int a, b, c;
  char d, e, f;
  cin >> a >> d >> b >> e >> c >> f;
  vis[a]++, vis[b]++, vis[c]++;
  arr[2] = max(a, max(b, c));
  arr[0] = min(a, min(b, c));
  vis[arr[2]]++;
  vis[arr[0]]++;
  for (int i = 0; i <= 9; i++) {
    if (vis[i] == 1) {
      arr[1] = i;
      break;
    }
  }
  if (a == b && b == c && d == e && e == f)
    cout << 0 << endl;
  else if (d == e && e == f && arr[0] + 1 == arr[1] && arr[1] + 1 == arr[2])
    cout << 0 << endl;
  else if ((a == b && d == e) || (a == c && d == f) || (b == c && e == f))
    cout << 1 << endl;
  else {
    if (abs(a - b) == 1 && d == e)
      cout << 1 << endl;
    else if (abs(a - c) == 1 && d == f)
      cout << 1 << endl;
    else if (abs(b - c) == 1 && e == f)
      cout << 1 << endl;
    else if (abs(a - b) == 2 && d == e)
      cout << 1 << endl;
    else if (abs(a - c) == 2 && d == f)
      cout << 1 << endl;
    else if (abs(b - c) == 2 && e == f)
      cout << 1 << endl;
    else
      cout << 2 << endl;
  }
  return 0;
}
